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.

Dark GDK / How do I properly make gun accuracy?

Author
Message
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 1st Jul 2009 22:40 Edited at: 1st Jul 2009 23:08
Hi! I have my gun and when I shoot it hits a random place and that's all good but the area that it will randomly hit is in the shape of a rectangle so how could I shoot randomly in a circle?

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 2nd Jul 2009 00:44
Show us the relevant part of your code.

The answer will lie with the sin and cos functions but I need to see how you are getting your rectangle first.
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 2nd Jul 2009 01:19
Ok, it's really simple, all I use is this:


Then it's the collision stuff but that's not needed

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 4th Jul 2009 00:26 Edited at: 4th Jul 2009 00:30


All I could do is guess as I can't run your code.

Here is the theory, I think.

if you have the two equations:
float x = dbSin(angle);
float y = dbCos(angle);

If you feed different angle values into the equations you will always get co-ordinates of the circumference of a circle with radius of unit length(1). You can change the radius by multiplying the result as you see fit.

In your case, angle will be your random number.

EDIT: You might want to work out the random number first and use the same value for x and y.

If you cant get it to work, try writing a little simplified demo which I can run.
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 4th Jul 2009 01:22
Thanks, it worked!


Use Google first... it's not rocket surgery!

Login to post a reply

Server time is: 2024-10-01 05:48:55
Your offset time is: 2024-10-01 05:48:55