Rocket moving towards object (enemy)?
Blitz3D Forums/Blitz3D Beginners Area/Rocket moving towards object (enemy)?
| ||
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! :) |
| ||
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, |
| ||
Check out my homing missile code at http://www.blitzbasic.com/codearcs/codearcs.php?code=2258 |
| ||
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# |
| ||
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. |
| ||
so yea, i need another way of going about this. |
| ||
Alternatively you could just do this: each frame: pointentity myrocketentity,mytargetentity moveentity myrocketentity,0,0,velocity# |
| ||
wouldnt 'each frame' be a LITTLE too much? |
| ||
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. |
| ||
ok. cool. so this will pin point my rocket to the target instead of make it bounce off to a totally random location? |
| ||
Yes. |