Page 1 of 1

Bullet from a gun

PostPosted: Tue Jan 18, 2011 11:12 pm
by Granlord
Hello fellows!
was wondering if someone knows the formula to make a bullet come from the pipe of a gun(top down).
If i rotate my actor it gets unsystematic with the pipe. And i need to make the bullet to start a bit further, ells it looks like my actor is spiting the bullets..
I have tried this code and it wont work.

player -> keydown
Code: Select all
int i;
i = ActorCount("flames")-1;

CreateActor("flames", "flames", "(none)", "(none)", 0, 0, false);
getclone("flames.i")->x=player.x + 100 * radtodeg(cos(player.angle)) ;
getclone("flames.i")->y=player.y + 100 * radtodeg(sin(player.angle)) ;


I have used this formula in another game engine (director -__- and that shit is not to play with) and there it worked. Thought i have translate it.

Appreciate any help!
Cheers
Granlord

Re: Bullet from a gun

PostPosted: Wed Jan 19, 2011 4:10 am
by skydereign
If it's just a circle, this works. cos and sin will deal in radians, so you have to use the degtorad to convert the angle properly. Then it's just a matter of dealing with circles. Now, the getclone part shouldn't work. getclone will try to get "flames.i", not flames.0 or whatever i is. But, in this case it isn't necessary, just do this.
Code: Select all
CreateActor("flames", "flames", "(none)", "(none)", 0, 0, false);
flames.x=player.x+cos(degtorad(player.angle))*100;
flames.y=player.y-sin(degtorad(player.angle))*100;


Because you used CreateActor, flames will be an adequate reference to the created actor.

Re: Bullet from a gun

PostPosted: Wed Jan 19, 2011 12:44 pm
by Granlord
Hmm strange. When i used the radtodeg i assumed that it went from radian to degrees ^^. Well well, thanks for the help!

Re: Bullet from a gun

PostPosted: Wed Jan 19, 2011 7:50 pm
by Granlord
I tried the code when i got back from work, but I got the same results as before. The flame starts at the same position but 100 px away from the actor. And when i rotate my actor it wont follow :(
Got any idea?

Re: Bullet from a gun

PostPosted: Thu Jan 20, 2011 1:07 am
by skydereign
How are you rotating your actor? If you are just using animpos then it won't work. If you are using angle, and still having problems, I can post a demo of it if you want.

Re: Bullet from a gun

PostPosted: Thu Jan 20, 2011 12:47 pm
by Granlord
Both of them. :)

Re: Bullet from a gun

PostPosted: Fri Jan 21, 2011 4:26 am
by skydereign
Okay, well what might be causing the problem is your use of angle. The angle variable will remain zero if your actor is not using directional_velocity, so since your gun is still it will not keep the value of your angle. If this is the problem, to fix it, create another variable, in this example it is called ang. I made it an actor variable, just in case you have other guns. So, when you need to change angle, or use it for the bullet's create, use ang instead. But, when dealing with directional_velocity, you have to use angle, instead of ang.

Re: Bullet from a gun

PostPosted: Fri Jan 21, 2011 5:39 pm
by Granlord
I now understand the problem, and solved it! I must say that its not something you count on that the angle value is zeroed at once. Thanks for the help! This problem have bugged me for too long now! :D