They move along a line, following a direction vector, at some speed…
They bounce off walls and such, in an elastic reaction, ie, they never lose speed.
I use them for paddle games and place holders, and much more.
Using them currently, as a grenade, so nades bounce off walls and stuff, and explode after 3 or 4 seconds.
But they need gravity… normally, for an object to “fall”, I would just add a float for gravity, accelerate the gravity over time, and ADD the gravity to an objects normal movement, reseting gravity and stopping grav. accel. when grounded…
But these nades bounce off angled surfaces and floors, so how do I control for that, when it comes to gravity acceleration?
Ok, I’ve been trying to post back for quite some time, but end up deleting it, for rambling…
Seems something like: When the ball bounces, however much its direction just changed from that,
it should lose some momentum ie direction… AND gravity should be reduced by the same factor? (from 0 to 1)
You’re talking about two different concepts I think.
Gravity is a force that is constantly applied in a single direction. Unless your specific gameplay mechanics want it to, this never changes. It’s an optimization for you to disable gravity when it can no longer apply (ie, grounded), but technically it never goes away.
Energy loss due to imperfect elastic collision. A fraction of an object’s energy is lost when it bounces.
It’s my quick way of doing gravity, because I think “real” gravity is too fast, for the small screen real estate…
So I just have a float for “total_gravity”, which I increment by a small amount each frame, up to a max.
Then the “total gravity” is applied to the objects position.
When a thing touches floor, “total gravity” is set to zero, and it stops falling…
Works fine for most things, because they grip a surface, or explode or whatever…
elastic reaction balls are simple too, in concept anyway.
But combining the 2 I don’t even know where to start.
-Right now, I just set gravity to zero when I bounce on something BELOW the ball… It is a fair approximation, but it’s not as COOL as I feel a more real system would be…
here is my relevant code
BOUNCE: … this checks the impact point on the ball (cross point) to see if the bounce happened below the ball, ie a floor… IF it is floor, reset gravity… And for ANY surface hit, deposit some energy.
I think you’re maybe going a bit too far afield here. We can go back to some basics and build up from there. Let’s take bounce energy loss out of the game for a minute here and just consider gravity. There’s some physics formulas that can be useful here.
A change in position over time can be described by d = t * v, where,
d = a change in position (delta distance)
t = a change in time (delta time)
v = velocity, or, the amount of distance something moves for a given period of time.
A change in velocity over time can be described by v = a * t, where,
v = a change in velocity
a = acceleration, or, the amount velocity changes over time.
t = a change in time
Consider these and how they can move your ball by updating your ball’s velocity over time, as well as updating your ball’s position over time.
You’re welcome to keep using the approach you’re using, but it makes it a bit harder to sort out any issues because your forging your own path.
If you give the above a try and run into issues, let me know. It’s been a while since I’ve done this so I’m going to play around a bit on my own haha.
Hi BOTH you guys! I can only tag one of you, it seems-
But I THINK I got it now!
balls direction (normalized) Y component is the factor for gravity…
so, increment float gravity each frame by some nice looking number, 0.02 or so in my case…
add this float gravity to balls Y dir each frame… then for every BOUNCE, multiply gravity by a number between 0 and 1, corresponding with normalized dir Y component…
And then I also on bounce, scale the overall direction vector by 0.9f to deposit some energy.
I’m glad you got it working in a way that you like
Consider though that I think you’re confusing gravity, an acceleration, with velocity. You should not modify gravity, but you should use gravity to modify your velocity. Velocity is what changes your position.
From what I can tell, that’s ultimately what you’re doing… you’re just using the wrong terms to describe it? Keep that in mind in case you ever need to debug this later, or share it with someone else.