Question by
arthurptj · Nov 14, 2015 at 02:28 AM ·
movementvector3speedmove an object
ridgidbody AddForce in direction player is pointed?
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
}
Comment
Answer by joemane22 · Nov 14, 2015 at 05:23 AM
If you want to get the direction the players sprite is facing you can use transform.forward. If that's not what you want then please be more specific.
i need to use AddForce to create acceleration not use transform.forward for an instant velocity.
rigidbody.Addforce(transform.forward * strength);
Your answer
Follow this Question
Related Questions
Stop moving gameObject and push it back 0 Answers
DOTween sequence snapping 0 Answers
Speed boost button for player 0 Answers
Vector3 magnitude broken? 1 Answer
collision is making its own vector 1 Answer