I am having a difficult time with the code below. Whenever I make a new object, I want the object to fall where the mouse pointer is; likewise, whenever I select an object with the mouse, I want to move the object from where it was. When ever I try to do either, the object seems to "jump start" from a random location.
sync on
do
if spacekey() = 0 then spacedown = 0
if spacekey() = 1 and spacedown = 0
spacedown = 1
obj = find free object()
make object cube obj, 10
inc numObjects
dist# = 4 * object size(obj)
pick screen mousex(),mousey(), dist#
x# = get pick vector x()
y# = get pick vector y()
z# = get pick vector z()
position object obj,x#,y#,z#
bSelected=1
endif
if obj > 0 and bSelected=1
x# = x# + (mousemovex()*0.1)
z# = z# - (mousemovey()*0.1)
y# = y# + (mousemovez()*0.01)
position object obj,x#,y#,z#
position mouse object screen x(obj), object screen y(obj)
endif
if mouseclick() = 0 then rightmousedown = 0
if mouseclick() = 2 and rightmousedown = 0
rightmousedown = 1
bSelected=0
endif
if mouseclick() = 0 then leftmousedown = 0
if mouseclick() = 1 and leftmousedown = 0 and bSelected=0
leftmousedown = 1
obj = pick object (mousex(),mousey(),1,numObjects)
if obj > 0
bSelected=1
endif
endif
sync
loop