I find my self extremely confused currently with the default movement script atm, and I was wondering if is possible to make my own simpler movement script that had the following features.
-w,s,a,d Movement
-slop following and edge dropping (from what ive tried I only had objects move threw walls and hills and not drop off anything)
-collision
Do i need to make a simpler collider to go with my new script ?
Could someone please give me a nudge in direction I need to go to accomplish this, and some scripts I might use to do so ?
I really want to learn to make everything myself, and make it simple until I understand everything better and can add stuff more complex.
You should take a look at the Third Person MMO Controller package on the Unity asset store. Included is some simplified, well commented, code for both camera and character controls.
for your w,a,s,d Movement you can use use Input.GetAxis(“Vertical”) and Input.GetAxis(“Horizontal”) it will work.
function Update{
var x = Input.GetAxis("Horizontal");
var z = Input.GetAxis("Vertical");
transform.Translate(x*Time.deltaTiem,0,z*Time.deltaTime);
@script RequireComponent(CharacterController)
}
for your slop following, edge dropping you should use Character controller and for collision detection you must add Rigidbody to your character.
and for experience in character movement you can learn FPS tutorial provided by unity, they explain the whole thing nicely.
that’s what i can do for you now, i think this might help a little bit.
Ok and I was wondering, how would I use w,s,a,d input buttons (when i make them seperate) insteal of just the vertical and horizontal ones. I figure having it like that is more common and easier for noobs to the game to notice when keymapping.
I have a problem I tried adding a rigidbody and using translate, doesnt work. I tried something diffrent and it worked, but it doesnt drop or collide at all it just moves and stops right in the spot I stopped pressing the button.
wow! that’s never happens with me. I have used transform.Translate many time on my gameObject having Rigidbody, they always collide and drop. I think you are doing something wrong, could you please show me your code.
function FixedUpdate () {
// Input Controls.
var w = Input.GetAxis("Forward");
var s = Input.GetAxis("Backward");
var a = Input.GetAxis("Left");
var d = Input.GetAxis("Right");
//Walking.
if(Input.GetButton("Forward")){
transform.Translate(a*Time.deltaTime,0,w*Time.deltaTime);
}
}
I am trying to have the forward left right and back buttons seperate for the movement so that players see that instead of the vertical and horizontal stufff XD
However I tried first with those and they just wen straight and never dropped.
by chance could you make a example scene that I could disect ?
Ok I fixed it. However I cannot figure out how to make surethe capsule doesnt rotate when im moving against a cube, I have a camera and it is suppose to always look the direction of my camera though.
Movement
var MoveSpeed = 3.5;
var JumpHeight = 3.5;
function Update () {
var PlayerDirection =
var w = Input.GetAxis("Forward");
var s = Input.GetAxis("Backward");
var a = Input.GetAxis("Left");
var d = Input.GetAxis("Right");
transform.Translate((d-a)*MoveSpeed*Time.deltaTime,0,(w-s)*MoveSpeed*Time.deltaTime);
}
camera script
function Update () {
var x = Input.GetAxis ("Mouse X");
transform.rotation = (0, x, 0);
}
why do you want (forward(w) left(a) right(d) and back(s)) buttons separate, see you are getting those by default, In EDIT->PROJECT SETTING->INPUT You can see in Horizontal and Vertical they have given Alt native button as W,A,S,D. No one is going to see do you use Horizontal, Vertical or W,A,S,D then why? @gore23 see how simple this script is for the character movement
var speed = 10;
function FixedUpdate () {
transform.Translate(Input.GetAxis("Horizontal")*Time.deltaTime*speed,0,Input.GetAxis("Vertical")*Time.deltaTime)*speed;
}
and for camera i made this script now it rotate the player to prevent from colliding to a cube, just you need to rotate your mouse
var speed = 20;
var Player : GameObject;
function Update ()
{
var x= Input.GetAxis ("Mouse X");
Player.transform.Rotate( Vector3(0,x,0) * Time.deltaTime* speed, Space.World);
}
and add rigidbody component to your gameObject and see it will collide fall from hight .
Well when your changing controls you see the vertical+ vertical- inc… and that just sorta wierd to me since I have normally seen forward, backward,Left,andRight. I got it working with the those, but I encountered a problem that both ways have. The player will jiggle when hes moving against a wall, and if jumping, gets stuck slowly going down the wall. How would I fix this?
I also was wondering what was a ideal way to add a smooth jump.
you can use “the Force” when jumping, that way your rigidbody will fall down and act realistic, because of the gravity. I am referring to rigidbody.AddForce(new Vector3(0, 1, 0) * forceMultiplier), it’ll be smooth since the physics will calculate all there is to calculate.
on the other hand, if you don’t want to use physics to make you char jump, you can use Vector3.Lerp(transform.position, new Vector3(transform.position.x, transform.position.y + height, transform.position.z), Time.deltaTime * multiplier) or something similar.
you can even move the character using rigidbody.AddForce() or smt similar to make it more smoothy-smoothy.
the thing with the collisions might be caused by many things, one of which might be the fixed time step (edit->project settings->time->fixed time step [search time manager on unity manual]) or some other problem i can think of might be the min penetration for penalty (which is the amount a collider can enter another one before triggering anything [you can find and edit those settings in edit->project->physiscs-> min penetration penalty, lower that down a bit])
also make sure you have useGravity enabled and isKinematic disabled in the inspector on your rigidbody.