Move the model with the mouse

Blitz3D Forums/Blitz3D Beginners Area/Move the model with the mouse

panton(Posted 2007) [#1]
I have a 3d model, and If the mouse hits a location on the terrain, then the model have to move to there.

How to make something like this?


(srry for my english :P )


Rob Farley(Posted 2007) [#2]
http://www.blitzbasic.com/b3ddocs/command.php?name=CameraPick

To find the location.

Then place a pivot at that location

Then point your entity towards it and move it in that direction taking into account surroundings and terrain height.


panton(Posted 2007) [#3]
Then place a pivot at that location

Then point your entity towards it and move it in that direction taking into account surroundings and terrain height.


howto make that, code plz


Matty(Posted 2007) [#4]

if mousehit(1) then 

camerapick camera,mousex(),mousey()
if pickedentity()<>0 then 
     positionentity pivot,pickedx(),pickedy(),pickedz()

endif 
endif

pointentity yourentity,pivot
moveentity yourentity,0,0,speed#
positionentity yourentity,entityx(yourentity),terrainy(terrain,entityx(yourentity),0,entityz(yourentity)),entityz(yourentity)
 



I'll let you flesh it out from there.


panton(Posted 2007) [#5]
okay but last question :P

how to move the model to it because
moveentity yourentity,0,0,speed# dont work :P

and 1 more:

pointentity yourentity,pivot
i dont want that he points to pickedx() How to do this :P

ok thanks


Matty(Posted 2007) [#6]
You have to set 'speed#' to a non-zero positive value for it to work.

If you want the unit to remain in an upright position, facing the pivot but not tilting then a better way would be to do this:

aligntovector yourentity,entityx(pivot)-entityx(yourentity),0,entityz(pivot)-entityz(yourentity),3,1


panton(Posted 2007) [#7]
aligntovector yourentity,entityx(pivot)-entityx(yourentity),0,entityz(pivot)-entityz(yourentity),3,1

i dont understand this : entityx(pivot)-entityx(yourentity

what do u mean with that?


Rob Farley(Posted 2007) [#8]
the easiest way to keep your guy upright is to position the pivot at the same height as your player before pointing the player at the pivot.

positionentity pivot, entityx(pivot),entityy(player),entityz(pivot)
pointentity player,pivot


panton(Posted 2007) [#9]
positionentity pivot, entityx(pivot),entityy(player),entityz(pivot)
pointentity player,pivot

didn't u test this before, there is a bug in it when u
click behind the player, then the model looks up.


Rob Farley(Posted 2007) [#10]
No I've not tested any of the code I've given you. You seem to assume people are going to write code for you without you trying anything yourself.

Get off your backside and actually try something yourself.


panton(Posted 2007) [#11]
if pickedentity() = testentity then
<do something>
end if

This code dont work why not