x


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.

http://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!

more ▼

asked May 27 '12 at 03:27 AM

TotalityClause gravatar image

TotalityClause
15 3 4 4

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered May 27 '12 at 03:45 AM

hathol gravatar image

hathol
1.6k 4 11

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2245
x1862
x254

asked: May 27 '12 at 03:27 AM

Seen: 596 times

Last Updated: May 27 '12 at 03:45 AM