- Home /
rigidbody.velocity
Hi guys! Have a little problem - can't move my object (your tutorial about space shooter)
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour
{
public float speed;
void FixedUpdate ()
{
float moveHor = Input.GetAxis("Horizontal");
float moveVer = Input.GetAxis("Vertical");
Rigidbody rb = GetComponent<Rigidbody>();
Vector3 move = new Vector3 (moveHor, 0.0f, moveVer);
velocity = move * speed;
}
}
Answer by DoTA_KAMIKADzE · May 24, 2015 at 12:52 PM
rb.velocity = move * speed;
Also I'd highly recommend to store reference to rigidbody only once instead of every time on FixedUpdate, you can see and example of how to do it THERE.
Answer by TwinPrime · May 24, 2015 at 02:59 PM
GetAxis is a float func, between 0f and 1f.
U must have a higher force point, or use;
gameObject.GetComponent<Rigidbody>().AddForce(new Vector3
(moveHor*speed*Time.deltaTime,0.0f,moveVer*speed*Time.deltaTime);
or yes, use DotA's solution :)
Your answer
Follow this Question
Related Questions
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Can an instantiated object inherit its parent's velocity? 2 Answers
How do I make rigidbody.velocity in local space? 1 Answer
Updating Velocity for a Rigidbody Collision 1 Answer
Increased projectile velocity when holding button down 2D 1 Answer