0
\$\begingroup\$

This is a noob question but, what is the rigidbody movement equivalent of:

transform.position += transform.right * speed * Time.deltaTime;
\$\endgroup\$
1
  • \$\begingroup\$ Why do you want to know? \$\endgroup\$
    – Engineer
    May 16, 2020 at 18:30

1 Answer 1

0
\$\begingroup\$

It's:

Vector3 newPosition  = transform.position 
                     + transform.right * speed * Time.deltaTime;

rigidbody.MovePosition(newPosition);

or

rigidbody.velocity = transform.right * speed;
\$\endgroup\$
3
  • \$\begingroup\$ Shouldn't I be using Time.fixedDeltaTime instead of Time.deltaTime? \$\endgroup\$ May 9, 2020 at 18:01
  • \$\begingroup\$ If you're doing this in FixedUpdate, deltaTime returns fixedDeltaTime automatically. If you're not doing this in FixedUpdate, then you want to be using the actual timestep of your frame, which is deltaTime. So in both cases, deltaTime is what you want. It's rare that you should need to access fixedDeltaTime manually. \$\endgroup\$
    – DMGregory
    May 9, 2020 at 18:05
  • \$\begingroup\$ Ok. Thank you!! \$\endgroup\$ May 9, 2020 at 18:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .