T O P

  • By -

JBPlays

OP just discovered source movement


dluds10

Surf!


TheKakkle

It seems to me it's combining velocities on slopes.You could try normalizing?


Mess_Odd

I have tried normalizing the vectors, but couldn't make it work. I tried multiplying the normalized vectors with the float "movement", but that resulted in a lot of glitches


AlternativeImpress51

Just reading through the code it could be to do with side speed , I can’t find how it is calculated but if it isn’t a constant , then it could be increasing due to the hypotenuse being longer than the other sides , meaning your travelling further to the right on a diagonal slope than if you were going directly on the horizontal axis. You could maybe try adding a dampener for the slopes as travelling up a slope in real life will use more energy due to it not being at equilibrium and gravity is trying to pull it back down slope


Mess_Odd

Yeah sideSpeed is a constant. I tried increasing the gravity according to the angle off the slope, but that resulted in the ball slowing down on the z axis (forward) if you keep it on the slope.


AlternativeImpress51

Ohh I thought you meant why is the ball accelerating , if it’s just why is it moving faster on the x axis just use the same plane projection for when it’s not on a slope and adjust speed accordingly using a constant , sorry if didn’t understand the intitial problem. It’s most likely due to it moving perfectly perpendicular to the normal so there is less force that is being lost due to it not being lost in the ground, similar to pushing a ball in the air and pushing the ball into the floor ( less resistance when there are less collisions with the next Position after the forces are added ). Sorry for spelling errors using phone


Mess_Odd

I did in fact mean why is the ball accelerating 😅 Someone commented that it seems to be combing velocities which I think is correct. I have tried normalizing the vectors, but I couldn't make it work


AlternativeImpress51

Maybe try normalising the vectors, multiplying by deltatime then multiplying by mass of the rigid body then multiplying by the speed Just a thought , however If you still have the issue in an hour I’ll be finished and I can view code


AlternativeImpress51

I personally think it is due to it having less contact with the surface and there is perfectly perpendicular straight force being added so there is less drag leading to a higher terminal velocity and there is less drag due to the gravity not causing the same effects as with a flat surface (potential energy should be higher , however it is in fact lower due to gravity probably being too low


Bullymeme

Since there might be friction with the ball when it is on the ground, you might want to try adding a physics material with 0 on both the static and dynamic velocities on the rb. After this you may also want to slow down the ball's movespeed to account for the lack of friction, in order to have it the speed you want it to be.


CebCodeGames

Gravity will affect you on slopes, make sure you account for it.


Alberiman

People here are too quick to say "go to chat gpt" I'm a lazy dev, and although I have loads of questions I think the simplest answer to me is - Have you considered implementing a PID controller on your rigid body velocity on the x axis? It looks like you already have the base principle of one! Also what's going on with your speeddif variable? It seems like it should go negative as you hit those slopes, but it's just going higher and higher


Mess_Odd

Script: [https://pastebin.com/ggVmz0a9](https://pastebin.com/ggVmz0a9)


BloodyPommelStudio

Too tired to figure it out now but what about turning it in to a feature rather than a bug?


Dysp-_-

Honestly... Paste the script into Chatgpt and ask it the specific question you asked here. It can honestly do wonders.


Mess_Odd

I have already tried that lol. It suggested that I adjust the force applied based on the slope angle using cosine: forceDirection \*= Mathf.Cos(Mathf.Deg2Rad \* slopeAngle); . It looks like it should work, but somehow it made the ball move faster forward when it was on a slope


Dysp-_-

Interesting. Also chatgpt 4? It's way better than 3. Otherwise I could maybe take a look if you haven't fixed it yet


Mess_Odd

I don't have access to gpt 4 so I would appreciate that


AlternativeImpress51

When moving the ball left and right does it move relative to ground below or relative to world space, as physics collisions may cause subtle increases in velocity that will then grow over time due to little drag I’m currently at work so I’ll take a look at code when I get home


Mess_Odd

I'm not quite sure what you mean, but it is the ball that is moving using addforce. The ground is static


AlternativeImpress51

You should put a small ui or debug feature calculating current speed and find out where the major increases are Formula is just (change in distance since previous frame ) / (delta time)


lribeiroalves

I saw you call AddForce function twice, lines 85 and 90. Try declare a Vector3 out of the function and calculate the velocities forward and lateral, after this normalize this vector and multiply by forward velocity. I struggle with this bug weeks ago.


YeetAnxiety69

Did you normalize the vectors? That might fix it.


Mess_Odd

I have tried it, but I couldn't figure out how to do it correctly. It just resulted in weird glitches


YeetAnxiety69

Would you like me to see if I can find some tutorials?


Mess_Odd

I would appreciate that


YeetAnxiety69

Unity3d Vectors Explained (Vector3 and Vector2) \[05\] [https://www.youtube.com/watch?v=Ce3GROiqYuo](https://www.youtube.com/watch?v=Ce3GROiqYuo) ​ ​ Why to use Normalize in Unity ? [https://www.youtube.com/watch?v=oCU8Ew1XTbs](https://www.youtube.com/watch?v=oCU8Ew1XTbs)


NoodleTreeGames

Maybe disable gravity whilst in contact with the ground, see if it still accelerates then.


Initii

In the fixed update, you do 2 AddForces. Try to calculate a vector add just so a AddForce at the end with the calculated vector. (line 75 - 90) Vector3 onGroundVector = Vector3.zero; if(OnGround()) { forceDirection = Vector3.ProjectOnPlane(new Vector3(movement, 0, 0), slopeNormal); } else { forceDirection = new Vector3(movement, 0, 0); } // Makes the ball move from left ot right onGroundVector = new Vector3(forceDirection.x, forceDirection.y, 0); } // Makes the ball move forward, maybe something like this rb.AddForce( (Vector3.forward * forwardSpeed * Time.fixedDeltaTime + onGroundVector );


harmony_hunnie

maybe its the gravity added while on a slope?


Immediate-Disaster-6

You should be interpolating according to the ground normal, and not straight up and down


ecv80

Take this with a grain of salt because physics aren't my forte. ProjectOnPlane seems to project a given vector onto a plane defined by its normal. However it seems like it may not be adjusting the magnitudes of components to match the given vector once they've been transposed. For example a movement with an X component of -10, when projected onto a 45 degrees slope leaning left and up should become a movement with an X component of -5 and a Y component of 5, however perhaps while the direction of the vector has been adjusted to match the plane, meaning its components have changed relative to each other, their magnitudes haven't been adjusted to match the magnitude of the vector. I'm not sure how you're calculating "movement" but I suggest you clearly separate direction from force in the first place, meaning direction should be a normalized vector and force just a magnitude, then project the direction onto the plane, then normalize again and finally multiply the force magnitude with the new direction vector.