Hi,
I have sphere for which I have added rigidbody. After adding the rigidbody code I have used to move object and rotate object is not worked and when trying to move object it shakes the base in which it lie. So I have search through google find that I can’t use tranform.Translate
and transform.Rotate
for the rigidbody so, I have used the MovePosition
and MoveRotation
methods. but when I try to move my object it is moving in one direction. i.e direction that I have set in my vector here rigidbody.MovePosition(rigidbody.position + (new Vector3(movementX*speed,0,movementX*speed)));
I have used this code to move rigidbody.
using UnityEngine;
using System.Collections;
public class movement : MonoBehaviour {
// Use this for initialization
public float speed=20f;
public float rotation=50f;
void Update () {
float movementY=Input.GetAxis("Horizontal")* Time.deltaTime;
float movementX=Input.GetAxis("Vertical")* Time.deltaTime;
// movementX*=speed;
// movementY*=rotation;
Quaternion deltaRotation = Quaternion.Euler(new Vector3(0,movementY*rotation,0));
rigidbody.MovePosition(rigidbody.position + (new Vector3(movementX*speed,0,movementX*speed)));
rigidbody.MoveRotation(rigidbody.rotation *deltaRotation);
}
}
problem is rigidbody is moving in only one direction. i.e direction that I have set in Vector…When I try to move it with transform.Translate
it is not working and the ground is shaking when try to move.