x


How to move rigidbody Diagonal with movePosition

var player :Transform;
var speed = 10;
private var direction = Vector3(0,0,0);

private var grounded = 0;

function Update () {
walking = speed  * Time.deltaTime;



if(Input.GetKey("w"))
player.rigidbody.MovePosition(player.position + player.forward * walking);

if(Input.GetKey("d"))
player.rigidbody.MovePosition(player.position + player.right * walking);

if(Input.GetKey("a"))
player.rigidbody.MovePosition(player.position + player.right * -walking);

if(Input.GetKey("s"))
player.rigidbody.MovePosition(player.position + player.forward * -walking);

if(Input.GetKey("w") && (Input.GetKey("d")))
player.rigidbody.MovePosition(player.position + player.forward.right * Time.deltaTime);




}

there's my whole script so far, and i have seen other for controlling rigidbodys, but i dont what to have a script i cant understand so im making my own, i don't want to use add Force, but if i dont then there is no diagonal its either straight or sideways. how do i make a dagonal?

more ▼

asked Jun 12, 2011 at 04:27 PM

Ninjaoboy gravatar image

Ninjaoboy
11 15 12 12

It's a lot easier if you use GetAxis instead of a bunch of keys.

Jun 12, 2011 at 04:40 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Accumulate a 'delta' in a Vector3, then apply it with MovePosition at the end

more ▼

answered Jun 12, 2011 at 04:42 PM

DaveA gravatar image

DaveA
33.3k 416 335 442

Could you help me understand that better, i am kind of a noob in scripting, also if it is a Vector3, wouldn't it be the world-wide x,y,z coordinates, they need to be local.

Jun 12, 2011 at 06:44 PM Ninjaoboy
(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:

x3052
x2133
x1603
x824
x27

asked: Jun 12, 2011 at 04:27 PM

Seen: 2005 times

Last Updated: Jun 12, 2011 at 06:44 PM