Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Comparing angles #389583
12/15/11 23:06
12/15/11 23:06
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
I'm trying to set up a script for a bullet that can ricochet. It's working perfectly, except one thing. I want the bullet to bounce only if it strikes a glancing blow on an obstacle. For instance, if it hits an object straight on, it doesn't bounce. If the surface is more than say 70 degrees perpendicular to the bullet's trajectory, it does bounce.

I've messed with different ways of angle comparison and have not figured out how to do this.

Vectors available for this:
Bullet's current angle
Bullet's angle following a bounce
Normal of surface hit
Bullet's absolute velocity

Is there a function (or script) that simply examines two angles and gives me the total difference (a single number, not a vector) between them?

Re: Comparing angles [Re: MatAllum] #389586
12/15/11 23:17
12/15/11 23:17
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
In the event function:

vec_normalize(bounce,1);
alpha = abs(acos(vec_dot(normal,bounce)));

if(alpha > 70) do bounce;

Should work.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Comparing angles [Re: Superku] #389589
12/15/11 23:59
12/15/11 23:59
Joined: Jan 2005
Posts: 330
USA
M
MatAllum Offline OP
Senior Member
MatAllum  Offline OP
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
Thank you, I'll give that a shot!

Re: Comparing angles [Re: MatAllum] #390598
01/02/12 18:34
01/02/12 18:34
Joined: Dec 2000
Posts: 4,608
mk_1 Offline

Expert
mk_1  Offline

Expert

Joined: Dec 2000
Posts: 4,608
you should only calculate abs(vec_dot(normal, bounce)) and skip the acos because it's unnecessary. instead of alpha > 70 compare alpha > cos(70) which means you should calculate cos(70) once and enter that number in your code.


Follow me on twitter

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1