STILL cant use lengthdir functions properly -.-

F

fxokz

Guest
Once again i have a problem with lengthdir functions. I cant seem to understand the way they work. Im trying to spawn bullets at a particular part of a sprite even if it is rotating. I cant seem to get it right though.. Im using this code which is about as flawed as it gets.

Code:
a = instance_create(x-lengthdir_x(21, image_angle) , y-lengthdir_y(21, image_angle)+20, obj_bullet_enemy);
i dont know what im doing wrong..
 
M

McWolke

Guest
some more information would be nice.
why are you subtracting the lengthdir value? normally you would add it.
 

Bingdom

Googledom
An easy way to remember on how you use lengthdir functions properly is the way how they completely stick to another instance. It's done by doing some code like this:
Code:
///o_child
dir = point_direction(x,y,o_parent.x,o_parent.y);
dis = point_distance(x,y,o_parent.x,o_parent.y);

x = o_parent.x + lengthdir_x(dis,dir+o_parent.image_angle);
y = o_parent.y + lengthdir_y(dis,dir+o_parent.image_angle);
With this method, you can see that their position sitting on the main instance is determined by their angle and distance from it.

Now for the creation of the bullet, you may require some trigonometry.
You need to work out the distance from the centre of the sprite, and the angle.

If you want the bullet to spawn in front of the player, no new direction is required. Simply, something like this:
Code:
x = x+lengthdir_x(8,image_angle);
y = y+lengthdir_y(8,image_angle);
 
Top