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.

  1. 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. 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…


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;

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.