Hi, I’ve been trying to figure this out for days. Some codes I’ve tried work but not as quite as i want it to work. I have the shell ejection working fine when I use transform.translate but when i use AddForce the shells just floats to the left. I finally have the shell to rotate on its own axis as other codes i have tried would rotate it according to the position of its parent, which shows the shell floating all over the place. I also have a box collider comp on the shell but set as is triggered so it would not collide with the player collider. Not sure if that matters.
What am I doing wrong?
Any help will be appreciated!
My code:public class ShellEjectionCtrl : MonoBehaviour {
public float ejectSpeed;
public float rotspeed;
void FixedUpdate(){
transform.Translate(new Vector2 (-2,ejectSpeed)*Time.deltaTime); //this code works properly the shell gets affected by gravity but rotates weird like it has a point of rotation.
GetComponent<Rigidbody2D> ().AddForce (new Vector2(-2,ejectSpeed));//this code makes the shell float to the left position but shell rotates properly
GetComponent<Rigidbody2D> ().AddTorque (Random.Range (0, rotspeed));//rotates the shell not relative to its position i.e ejection port of the rifle
Destroy (gameObject, 2.0f);
}
}