- Home /
Other
My object's direction angle changes after hit a collider in a certain velocity, but also not change in different speeds.
I am using a float value for "speed" variable. And assign it "2.0f". I have a ball object and I give velocity to the ball in the start() function.
private float speed = 2.0f;
void start() {
rb = GetComponent(Rigidbody2D) ();
rb.velocity = new Vector2(speed, speed);
Debug.Log(rb.velocity); }
With 2.0f velocity value it always go in 45 degree angle and after hit objects stays in that angle. With 3.0f speed after sometime it slowly start to change it's angle. And same for 6.0f, 7.0f, 8.0f and 9.0f. But with speed of 4.0f, 5.0f and 10.0f it also stay in the 45 degree angle. Weird huh?
It is critical for me to that ball object stay in 45 degree for the game's purpose. The ball object is inside a 2d square field and there are 4 walls cover the field and some square obstacles inside the field and collectables also inside the field. For collecting collectables ball should move in certain angle but in different speeds it changes it's direction angle. In the inspector Ball's Collision detection is continuous, Interpolate = none and already tried speed*Time.deltaTime.
I am trying to increase the speed depend on amount of collected collectable. When collectable collected a trigger start to work call a function:
public void setBallSpeed()
{
float up = 2f;
var vel = rb.velocity;
rb.velocity = vel * up;
Debug.Log(rb.velocity);
}
When my speed is 2.0f with this function calculation my speed became 4.0f but here is the trick, normally 4.0f speed work good but when I increase speed in that way again I am facing with angle changing losing my straight direction.
Any idea? brainstorm? :)