Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Shoot bullet in facing direction

Author
Message
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 10th Nov 2012 05:02
I have been able to sort out how to shoot an animated bullet, but i can't figure out how to get the bullet to fire in the direction the player is facing. Right now the bullet will only fire to the right from the players position. Here is what I have so far. Thank you for any help you can give.

Attachments

Login to view attachments
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 12th Nov 2012 05:09
Use trig functions to determine the "dirx" and "diry" of your bullet based on the player's current facing angle.

An example (that may or may not work with your code, bt here for reference):



Note that bulletSpeed is used as a scalar here since cosine and sine only range from -1 to 1.

Hope that helps!


~Plystire

A rose is only a rose until it is held and cherished -- then it becomes a treasure.
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 12th Nov 2012 16:40
Thank you very much. Thats great... I'm very close now. I added your code in and the bullet now shots on angles as player rotates. But now it only shoots from the right side of the player. I need to work out how to get the bullet to shoot from the front of the player. Am I missing something?

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 12th Nov 2012 17:17
Add 90 to the angle you use to get the bullet direction (or it might be subtract 90, done by adding 270). I had to adjust my values so that my angles started with zero at the top and went clockwise for my game.

Cheers,
Ancient Lady
AGK Community Tester
sskethan
15
Years of Service
User Offline
Joined: 20th Sep 2008
Location: Oshawa, ON. Canada
Posted: 12th Nov 2012 17:35
That was it. So simple. Thank you. I added 90 to the angle.

Login to post a reply

Server time is: 2024-05-07 19:59:57
Your offset time is: 2024-05-07 19:59:57