- Home /
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
Answer by Meltdown · Sep 18, 2011 at 06:58 PM
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
Answer by CrowdedWorlds · Sep 19, 2011 at 12:09 AM
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 : )
Answer by Clunk · Sep 19, 2011 at 04:04 AM
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); }
}
Your answer
Follow this Question
Related Questions
Mixamo Character Movement 0 Answers
Why won't Character Controller Move Forward while in the Air? 2 Answers
3rd person controller, jump Error 1 Answer
movement doesnt stop when jump pad is tapped at the same time 0 Answers
Can't jump in C# 1 Answer