Question by
DozyRyan · Jul 02, 2017 at 07:00 PM ·
object movement
apply force in camera direction
so i have an object but i want to apply force in the direction between them so its moving forward. however my camera is hovering above the looking down on the object and i don't want there to be a downward force so how would i minus the camera height then get the direction to apply the force?
void Update() {
var camDir : Vector3 = Camera.main.transform.forward;
var inputDir : Vector3 = Vector3.zero;
inputDir.x = Input.GetAxis("Left_Horizontal");
inputDir.z = Input.GetAxis("Left_Vertical");
var dir : Vector3 = Vector3.zero;
dir.x = camDir.x * inputDir.x;
dir.z = camDir.z * inputDir.z;
rigidbody.AddForce(dir * force);
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612125343im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Object rotation as we see of the prefab in prefab window. 0 Answers
Object moves on itself, how to write an "if statement'? 0 Answers
controlling objects with a character controlled by a nav mesh agent 0 Answers
Grabbing object with mouse and placing/snapping it back to Original (indicated) Position 0 Answers
My random script work incorrect! 0 Answers