Bullet from a gun

Game Editor comments and discussion.

Bullet from a gun

Postby Granlord » Tue Jan 18, 2011 11:12 pm

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
Granlord
 
Posts: 9
Joined: Tue Dec 14, 2010 10:13 pm
Score: 0 Give a positive score

Re: Bullet from a gun

Postby skydereign » Wed Jan 19, 2011 4:10 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Bullet from a gun

Postby Granlord » Wed Jan 19, 2011 12:44 pm

Hmm strange. When i used the radtodeg i assumed that it went from radian to degrees ^^. Well well, thanks for the help!
Granlord
 
Posts: 9
Joined: Tue Dec 14, 2010 10:13 pm
Score: 0 Give a positive score

Re: Bullet from a gun

Postby Granlord » Wed Jan 19, 2011 7:50 pm

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?
Granlord
 
Posts: 9
Joined: Tue Dec 14, 2010 10:13 pm
Score: 0 Give a positive score

Re: Bullet from a gun

Postby skydereign » Thu Jan 20, 2011 1:07 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Bullet from a gun

Postby Granlord » Thu Jan 20, 2011 12:47 pm

Both of them. :)
Granlord
 
Posts: 9
Joined: Tue Dec 14, 2010 10:13 pm
Score: 0 Give a positive score

Re: Bullet from a gun

Postby skydereign » Fri Jan 21, 2011 4:26 am

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.
Attachments
angle.ged
(1.45 KiB) Downloaded 75 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Bullet from a gun

Postby Granlord » Fri Jan 21, 2011 5:39 pm

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
Granlord
 
Posts: 9
Joined: Tue Dec 14, 2010 10:13 pm
Score: 0 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron