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
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
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 : )
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);
}
}