how to move a selected 3d mesh to a other place with one mouse click

Blitz3D Forums/Blitz3D Programming/how to move a selected 3d mesh to a other place with one mouse click

GC-Martijn(Posted 2003) [#1]
H!

-I have a 3D world
-I have a 3D mesh
-I can select the 3D mesh and when this happend then
 object\selected = 1 


And I have this code below:

 
If MouseHit(2) 
  For object.thing = Each thing
     If object\selected = 1 Then

	;object\x = object\destX
	;MoveEntity object\entity,object\x,object\y,object\z
	
      EndIf
  Next
EndIf


What I want is:
I have a selected object
Then I click with my rightmouse a other place and the object must move there with a speed#

And the objects are later for example people and they can't fly , so the 3D y coordinate is 0 or something ¿

Well as you can see I need some help here
BTW I made a field with
object\pivot =CreatePivot()

and its at the same place as the object.

Thanks :]


Jeppe Nielsen(Posted 2003) [#2]
Do something like this:


dx#=(object\destX-object\x)
dy#=(object\destY-object\y)
dz#=(object\destZ-object\z)

;Distance to destination

dist#=sqr(dx*dx+dy*dy+dz*dz)

object\dx#=( dx#/dist# ) * object\Speed#
object\dy#=( dy#/dist# ) * object\Speed#
object\dz#=( dz#/dist# ) * object\Speed#

;move object

object\x=object\x+object\dx
object\y=object\y+object\dy
object\z=object\z+object\dz

PositionEntity object\Entity,object\x,object\y,object\z



Hope it makes sense :)


GC-Martijn(Posted 2003) [#3]
sounds cool but I don't have the

object\destX
object\destY
object\destZ

If you could say how to get these then I can make it (I think/hope)

Thank You Very Much Jeppe


Jeppe Nielsen(Posted 2003) [#4]
You could pick the destination coords with the mouse:


If MouseHit(2)
CameraPick(Camera,MouseX(),MouseY())

object\destX=PickedX()
object\destY=PickedY()
object\destZ=PickedZ()

EndIf




GC-Martijn(Posted 2003) [#5]
Cool Thanks
I must sleep now but tommorow late I can make it

If (tommorow == error) then
I'm at this topic
else
i'm working :)
end if



GC-Martijn(Posted 2003) [#6]
Damn one small thing is wrong and I don't know what .


	;move selected objects
	If MouseHit(2) 
	
	;get the rightmouse click 3D coordinates
	CameraPick(Camera,MouseX(),MouseY())
	destX=PickedX()
	destY=PickedY()
	destZ=PickedZ()
			
		For unit.soldier 	= Each soldier
			If unit\selected= 1 Then
		
			dx#=(destX-unit\x) 
			dy#=(destY-unit\y) 
			dz#=(destZ-unit\z) 

			;Distance to destination 
			dist#=Sqr(dx*dx+dy*dy+dz*dz) 

			unit\dx#=( dx#/dist# ) * unit\speed#
			unit\dy#=( dy#/dist# ) * unit\speed# 
			unit\dz#=( dz#/dist# ) * unit\speed# 

			;move object 
			unit\x=unit\x+unit\dx 
			unit\y=unit\y+unit\dy 
			unit\z=unit\z+unit\dz 

			EndIf
		Next
	EndIf



and above this code i have


UpdateWorld



	For unit.soldier 	= Each soldier
		PositionEntity unit\entity,unit\x,unit\y,unit\z 
			MoveEntity unit\entity,unit\x,unit\y,unit\z 
	Next

RenderWorld



the objects move to the wrong one , and goes up.
an example would be great :)

Thanks


Jeppe Nielsen(Posted 2003) [#7]
Does this help:

;move selected objects
	If MouseHit(2) 
	
	;get the rightmouse click 3D coordinates
	CameraPick(Camera,MouseX(),MouseY())
	destX=PickedX()
	destY=PickedY()
	destZ=PickedZ()
			
		For unit.soldier 	= Each soldier
			If unit\selected= 1 Then
		
			dx#=(destX-unit\x) 
			dy#=(destY-unit\y) 
			dz#=(destZ-unit\z) 

			;Distance to destination 
			dist#=Sqr(dx*dx+dy*dy+dz*dz) 

			unit\dx#=( dx#/dist# ) * unit\speed#
			unit\dy#=( dy#/dist# ) * unit\speed# 
			unit\dz#=( dz#/dist# ) * unit\speed# 

			;move object 
			unit\x=unit\x+dx 
			unit\y=unit\y+dy 
			unit\z=unit\z+dz 

			EndIf
		Next
	EndIf


UpdateWorld

	For unit.soldier = Each soldier
		PositionEntity unit\entity,unit\x,unit\y,unit\z 
	Next

RenderWorld



GC-Martijn(Posted 2003) [#8]
Srry I can see this sunday/monday then I'm at home.


BlitzSupport(Posted 2003) [#9]
See if this is any use...

http://www.blitzbasic.com/codearcs/codearcs.php?code=379


GC-Martijn(Posted 2003) [#10]
jeppe it still don't work :(
I'm going to try somethings with your script.

And that I try that very very big script what BlitzSupport say.

and some other things

Thanks


GC-Martijn(Posted 2003) [#11]
YES with some cola/coffee it works.
The solution was the 3d world pickmode 2.

//thanks Todd :)