Dear All,
I have just this simple issue which i am not able to resolve. I have this Jump Code which basically works on objects like spheres and cubes and all, but when i apply it on the Imported model then it does not work. Please help.
public class PlayerMovement : MonoBehaviour
{
private Rigidbody body;
public float jumpVelocity = 5;
// Start is called before the first frame update
void Start()
{
body = GetComponent<Rigidbody>();
}
public void Update()
{
body.AddForce(Vector3.up * jumpVelocity, ForceMode.Impulse);
}
}
What does “does not work” mean? Are you getting an error? Do you just have jumpVelocity too low for the mass you set on the rigidbody?
1 Like
Also check that the new model actually has the script on it. 
Ok here is my exact code, i have tried different Velocities, they all work on the sphere but not on the imported model. The new Model has the Scripts on it, becuase the movement control works on it. And yeah, no errors are being generated at all.
public class PlayerController : MonoBehaviour
{
public Animator anim;
private Rigidbody body;
public float speed;
public float rotationSpeed;
public float vertical;
public float horizantal;
public float jumpVelocity = 5;
CharacterController controller;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
body = GetComponent<Rigidbody>();
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
//PlayAnimation();
Jump();
}
private void FixedUpdate()
{
vertical = Input.GetAxis("Vertical");
horizantal = Input.GetAxis("Horizontal");
//body.velocity = (transform.forward * vertical) * speed * Time.fixedDeltaTime;
Vector3 velocity = transform.forward * speed;
//controller.Move(velocity * Time.deltaTime);
transform.Rotate((transform.up * horizantal) * rotationSpeed * Time.fixedDeltaTime);
if (Input.GetKey("w"))
{
controller.Move(velocity * Time.deltaTime);
}
else if (Input.GetKey("s"))
{
controller.Move((velocity*-1) * Time.deltaTime);
}
}
void Jump()
{
if (Input.GetKeyDown("space"))
{
//GetComponent<Rigidbody>().velocity = Vector3.up * jumpVelocity;
//controller.GetComponent<Rigidbody>().AddForce(Vector3.up * jumpVelocity, ForceMode.Impulse);
body.AddForce(Vector3.up * jumpVelocity, ForceMode.Impulse);
Debug.Log("Jumping");
}
}
Make sure you have “apply root motion” turned off on your animator component.
Thank you all for your time. But i figured it out by changing my code.