x


Simple Character Movement

hi im new to this scipting part but i really need a simple script for my charater the only thing that he shall do is to walk forward and backward and jump and if you have a camera to that i could also use that ;) hope you guys will help

more ▼

asked Sep 18 '11 at 06:56 PM

jannich840 gravatar image

jannich840
1 1 1 1

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

1 answer: sort voted first

Nobody is going to write your scripts for you. You'll need to do your own research and ask specific questions on parts of your script you might be having problems with.

Take a look at the FPS tutorial and go through it from start to end and learn and understand how everything was done there, and then apply what you learnt to your project. It always helps to understand whats going on, you'll never learn if people just 'give' you scripts.

Good luck :p

more ▼

answered Sep 18 '11 at 06:58 PM

Meltdown gravatar image

Meltdown
5.6k 18 25 49

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

Unity ships with a basic set of controllers in it's 'Standard Assets' which you can import and get going with quite quickly. If you're like me, you might find it handy to reverse engineer these and gain a lot more from the experience than just plonking them in : )

more ▼

answered Sep 19 '11 at 12:09 AM

HeyItsDaijoubu gravatar image

HeyItsDaijoubu
33 6 6 8

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

The best way is to use the First Person Controller asset built into Unity. But here is the SIMPLEST script option to at least teach you the minimal scripting part of it for now. I won't get advanced at all. Just attach this script to a box. Make that box a rigidbody. Attach the main camera to the box. Set the player_jump variable in the inspector. int means intriguer, which mean a number without a decimal(1, 2, 3, etc...) float means a number with a decimal (1.0, 2.000, 3.04848648, etc...) This script will make you walk forward / back, sideways with the horizontal and vertical axes (w,a,s,d), or arrow keys, and jump with the spacebar. Set gravity in edit / project settings / physics. when I do anything like (0,0,0), this is the axes (x,y,z). Whatever I put in these instances adds a value to those axes :) Like (0, player_jump, 0) in the script means 0 on x axis, player_jump value on y, and 0 on z.

var player_jump : int; var walk_speed : float;

function Update() { transform.Translate(Input.GetAxis("Horizontal") * walk_speed, 0,
Input.GetAxis("Vertical") * walk_speed);

if(Input.GetKeyDown("space")) { rigidbody.AddForce (0, player_jump, 0); }

}

more ▼

answered Sep 19 '11 at 04:04 AM

Clunk gravatar image

Clunk
186 1 1 3

(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:

x1365
x1040
x335
x101
x25

asked: Sep 18 '11 at 06:56 PM

Seen: 1035 times

Last Updated: Sep 19 '11 at 04:04 AM