Rocket moving towards object (enemy)?

Blitz3D Forums/Blitz3D Beginners Area/Rocket moving towards object (enemy)?

Guy Fawkes(Posted 2009) [#1]
How can I move my rocket object as a homing device towards my enemy object?

For some reason, it's "teleporting" the rocket towards to the enemy's position, instead of moving towards its target.

Code:


Thank you! :)


Matty(Posted 2009) [#2]
two useful commands:

example:


aligntovector myrocketentity,entityx(targetentity,true)-entityx(myrocketentity,true),entityy(targetentity,true)-entityy(myrocketentity,true),entityz(targetentity,true)-entityz(myrocketentity,true),3,0.1

;aligns myrocketentity's z axis to the vector in the direction of the target, but does not snap instantly, instead rotates gradually due to the 0.1 value being specified

moveentity myrocketentity,0,0,rocketvelocity#

;moves rocket in z direction as specified by rocketvelocity.

These examples should help,


Zethrax(Posted 2009) [#3]
Check out my homing missile code at http://www.blitzbasic.com/codearcs/codearcs.php?code=2258


_PJ_(Posted 2009) [#4]

it's "teleporting" the rocket towards to the enemy's position


This is why:
PositionEntity p\Objects\Entity, o\Position\x#, o\Position\y#, o\Position\z#


It looks like you are re-positioning the rocket entity ( p? ) at the location of the enemy object (o?)

You should use MoveEntity. ideally, first ensure the object is facing towards the target, then move it by the required amount only in a forwards direction

MoveEntity Entity,0,0,velocity#



Guy Fawkes(Posted 2009) [#5]
tried that. it "bounced" the rocket WAY from the z value of the target. X)

how could i use aligntovector in this code? cuz i tried that, and it didnt work either.


Guy Fawkes(Posted 2009) [#6]
so yea, i need another way of going about this.


Matty(Posted 2009) [#7]
Alternatively you could just do this:

each frame:


pointentity myrocketentity,mytargetentity
moveentity myrocketentity,0,0,velocity#



Guy Fawkes(Posted 2009) [#8]
wouldnt 'each frame' be a LITTLE too much?


Ross C(Posted 2009) [#9]
You'd need to. or else it will look very jerky. Those two commands will not be the cause of any major slowdown, so your safe to use them every frame.


Guy Fawkes(Posted 2009) [#10]
ok. cool. so this will pin point my rocket to the target instead of make it bounce off to a totally random location?


Matty(Posted 2009) [#11]
Yes.