Eqric
1
Hi, i am trying to get a bullet to rotate as it moves and is affected by gravity.
So if the bullet speed in 0m/s it will just rotate 90degrees and fall straight down.
My plan was to “make” a triangle of the “start” and “end” position of the bullet, ofc the start and end position changes alot during the bullets flight.
So my code looks like this
tempDistance = Vector3.Distance(startV,endV);
angle = Mathf.Rad2Deg * (Mathf.Asin(hightdecrease/tempDistance));
Vector3 test = new Vector3(angle,0,0);
transform.Rotate(test);
highdecrease is B in the picture above and i think tempDistance will be C.
But this doesn´t seems to work at all, i get very strange angles.
Is the math correct?
system
2
You could try this:
//This would be the maximum speed of you bullet
float maxSpeed = 900;
//This is where the bullet was last frame
Vector3 lastPos;
void Update () {
//Find the velocity in m/s
float velocity = (lastPos - transform.position)/Time.deltaTime;
//Set up a ratio that will be used to rotate the bullet. If the velocity is maxSpeed, then the rotation will be 0 (forward, else it will rotate towards facing down (Assuming that +Z is your forward axis)
transform.eulerAngles = new Vector3(velocity/maxSpeed * 90, transform.eulerAngles.y, 0);
//Set lastPos so we can get the velocity next frame!
lastPos = transform.Position;
}
Very rough, but if you implement code like this, it should do what you asked!
-AJ
Eqric
3
Thanks mate, i give this a try!