- Home /
Move object forward in relation to the player
If I Drag a object with the standard DragRigidbody.js I want to move it to left, right, forward and backwards.
Its simple if I just Do it with a Vector3.forward left right or whatever, but its always in the same direction then, doesnt matter where my character is looking at. So I want to do a "forward" in the direction where the player is looking. How do I do that?
Answer by rutter · Apr 07, 2012 at 10:57 PM
Given a particular GameObject, you can use the properties of its Transform.
Let's assume you have a reference to some GameObject. Let's name the reference player
.
If you need to find the player, you could do something like this:
var player = GameObject.Find("ThePlayer");
From there, you can get a few unit vectors:
player.transform.forward
player.transform.right
player.transform.up
(You could multiply these values by -1 to get their opposites)
The above values are basically similar to Vector3.forward
, right
, and up
, with the exception that they're relative to the player's current rotation.
Your answer
Follow this Question
Related Questions
Weird translation after instantiating on transform.rotation 2 Answers
Understanding Space.World and Space.Self: Character changing movement direction 1 Answer
How do drag and angular drag interact? 2 Answers
drag object including free rotation 0 Answers
How to make a player rotate in a direction with a slope of the ground. 0 Answers