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.

DarkBASIC Professional Discussion / make the fireball bounce off an area?

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 18th Sep 2010 22:02 Edited at: 18th Sep 2010 22:03
Hey guys!


Here's my problem:



I basically have 3 variables.

gravity - constant of the worlds global gravity
gravity_inc - this variable is subtracted by gravity to simulate a gravity curve of the object on the y axis.
speed - this variable is the current speed of the fireball (The speed variable only affects the x axis, not the y axis, where gravity_inc only affects the y axis, not the x axis).

I'd like to be able to calculate the new values for speed and gravity after the fireball collides with a surface using sparky's GetCollisionBounce functions, but I don't quite understand what they return yet. Neither do I know how I will be able to calculate an angle for the fireball with the two values gravity_inc and speed, calculate the bounce angle for the ball, and then calculate the returned angle back into the values gravity_inc and speed.

Any help is greatly appreciated

And if you are asking why Mewtwo is able to shoot fireballs, the answer is because Mewtwo is using Knucklefists animation set, which includes the fireball attack. It won't stay like this, but I had to do that to test Mewtwo's developing animation set.

TheComet

Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 19th Sep 2010 13:52
You can get the angles with trigonometry knowing the ball's positions at the impact and right before the impact. And you also need the angle of the surface it collides with.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 19th Sep 2010 15:49 Edited at: 19th Sep 2010 15:51
OK, so the angle of the fireball is atan(gravity_inc/speed), and I will need to add that angle to the surface angle to get the angle the fireball is hitting the surface, but I have no idea how to get the angle of the surface it collides with... I marked it here in purple as a question mark:



Any help?

TheComet

Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 19th Sep 2010 16:12
Doesn't the collision system you're using allow you to get the surface normal at the point of intersection?
Sixty Squares
20
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 19th Sep 2010 17:48
I could be completely wrong, but...

I think the SC_GetCollisionBounce X/Y/Z commands return components of a unit vector which indicates the direction the object should bounce in. You can imagine a right triangle where the bottom leg is the X Bounce (a length from 0 to 1) and the side leg is the Y bounce (a length from 0 to 1). The hypotenuse would then be the direction that the object should bounce in. Since it is a unit vector, the length of the hypotenuse would be 1. If you included the Z then there would be another component going in the Z direction.

So now you have the X Bounce and the Y Bounce in variables. What now? Since the values are between 0 and 1, I would multiply the Y Bounce by the object's current gravity amount, and the X Bounce by the object's current speed. These would be your new speed / gravity_inc values.

Something like this might work:


If negative gravity_inc is down, then you may need to multiply the new result by -1 in addition to multiplying it by by#.

If you still want the angle, I believe it would be atan(by#/bx#). This is because of the whole right triangle thing I mentioned earlier.

Keep in mind that this is all untested and I'm not sure if it will work, but hopefully it will .


Guns, cinematics, stealth, items and more!
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 19th Sep 2010 23:44 Edited at: 19th Sep 2010 23:45
Thanks 60[] for helping out Unfortunately, it didn't work... I found that the SC_GetCollisionBounce X/Y/Z commands return very strange values that I don't quite make sense to me...

However, what you described above brought me to the idea of using SC_GetCollisionNormal X/Y/Z, which returns a value ranging between -1 and 1. From that I was able to make this:

gravity_inc=SC_GetCollisionNormalY()*(0-(gravity_inc*0.8))
speed=speed+(SC_GetCollisionNormalX()*speed*2)


EDIT : Ah, Benjamin already said to use normals

The 0.8 in the gravity formula is to simulate decreasing gravity over time, and can be disregarded.

The problem I am still having is that the direction of the fireball is disregarded... So if I have a 45° plain, it will increase speed when the fireball hits it, but it will also increase speed when the fireball hits it from the other direction.

The same if I use a 315° plain : It will decrease the speed when the fireball hits it, but it will also decrease the speed when the fireball hits it from the other direction.

How could I prevent/fix this?

Thanks,

TheComet

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 20th Sep 2010 00:37
Hi TheComet,

I believe the correct way is using this equation:
new speed = old speed - 2 * normal * (old speed . normal)

I also thought the bounce commands return the coordinates of the point where it would be if it bounced off. Not sure about that one though.

Cheers!
Sven B

acelepage
22
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: Plattsville
Posted: 21st Sep 2010 20:56
What you need to do is calculate the angle of the sloped ground. Then subtract this angle from the bounce angle, so that the bounce angle is now bouncing off flat ground. Now calculate the bounce position by reversing the Y-axis vector (the direction of the force of gravity). Now add the original ground angle back, and you have the correct bounce angle.
I did this in a coding challenge back in Jan'09 where balls were bouncing on a 3D surface.

( 2b || !2b ), that is the question. The answer: true
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st Sep 2010 21:09 Edited at: 21st Sep 2010 21:43
Hang on everyone, Someone asked a question like this not too long ago and I came up with a solution using trig.

roite here:
http://forum.thegamecreators.com/?m=forum_view&t=175566&b=1

that's 2d using trig. If you want to use vectors and normals in 3d, that wouldn't be too hard either. The main concept that is being dealt with is "Negating the velocity of an object in the direction of its normal". where "velocity" and "normal" are both vectors.

[edit]

oh yeah that vector thing is also straightforward:
Vf=V-2*(N.V)*N

Vectors are super duper helpful for anything movement-related in video game programming. If anyone has interest in learning about them, check out "Vectors Don't Bite!".

Login to post a reply

Server time is: 2026-07-22 22:07:26
Your offset time is: 2026-07-22 22:07:26