- Home /
Rotating Camera, and Movement help.
I'm using This to make an item move,
if (Input.GetKey ("w")) { rigidbody.AddForce(Vector3.forward * 45); }
And i was 1. Wondering if there is a way to make the an item JUST move forward, instead of rotating it, which is what this causes the item to do. For example, i used a cube to test it out, and when it starts to move, instead of it "gliding" across the ground its edge stops it and it has to "flip" over.
Can i make a fixed camera that doesn't go with the rotation of the item? I have attached a camera and positioned it in the proper area for it to be a "hack and slash" (as i'm just learning right now) and when it does rotate the camera rotates with it. Now, if i get the object to stop rotating it would be fine, but i would love to know how to stop this.
3.How would i get the object to rotate based on direction while the camera is fixed? Meaning when i go forward its forward, left it turns and goes left, etc. etc.
4.in the (Vector3.forward *10); what is the substitution for "forward" for other directions? It's the only one in the script reference and -forward and backward don't work...
Thanks!
Answer by hathol · May 27, 2012 at 03:45 AM
Ok, for the movement: I would set the velocity directly instead of applying a force. So the code would be
if (Input.GetKey ("w")) {
rigidbody.velocity = Vector3.forward * speed * Time.deltaTime;
}
That should solve your fliping over problem. For the camera, instead of attaching it directly to your game object, you could add a script to the camera that tells it to follow the player. Could be something as simple as
Camera.transform.position = YourPlayer.transform.position + (Vector3)SomeOffset;
Camera.LookAt(YourPlayer.transform.position);
Vector3 has constants for forward, right and up. If you want the negative (like a "backward") you would write "-Vector3.forward" or "Vector3.forward * -1" Remember that Vector3.forward stays the same, no matter where your object is facing to. If you want the forward vector relative to the object (the objects z axis), you can use transform.forward instead. Hope that helped.
Your answer
Follow this Question
Related Questions
Instantiating bullet and moving forward with rigidbody 0 Answers
Prevent Rigidbody From Rotating 3 Answers
Airplane goes weird on collision (Rigidbody) 1 Answer
Rigidbody.addforce then rigidbody.rotation and movement along transform.forward 2 Answers
Is it advisable to apply forces and rotations on a same object? 2 Answers