Quantcast
Channel: Answers by "ThePersister"
Viewing all articles
Browse latest Browse all 99

Answer by ThePersister

$
0
0
Rigidbody.velocity is a Vector3 because it's not only an Amount of speed, it's also a Direction. If you wanted an object move forward for example, you would apply the following: using UnityEngine; using System.Collections; public class MovingObject : MonoBehaviour { public float m_speed = 20f; private Rigidbody m_rigidbody; void Start() { m_rigidbody = GetComponent(); } void FixedUpdate() { // Makes this object move forward at X speed. m_rigidbody.velocity = m_speed * transform.forward; } } To apply force in a different direction you would just change "transform.forward" to something else like, choose one to your liking: m_rigidbody.velocity = m_speed * Vector3.up; // Move Up m_rigidbody.velocity = m_speed * Vector3.left; // Move left m_rigidbody.velocity = m_speed * Vector3.right; // Move right m_rigidbody.velocity = m_speed * Vector3.back; // Move back I hope that helps, I'm always around for further questions, best of luck!! @Brylos

Viewing all articles
Browse latest Browse all 99

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>