|
Hi. Im writing a script for my player of a 2d style game, but i have some problems. I want to make a gameplay like super mario, that when i hold left arrow it rotates to the left side and with no extra rotating continues to going on left direction and same for the right direction.
here is my code:
(comments are locked)
|
|
on your player rotation code you have "transform.Translate(Vector3.right );" when the left key is pressed down, this is being added to the transform.Translate that occurred in your movement code, as that's what's causing it to speed up. Also in your rotation code I would change it to Input.GetKeyDown() rather than Input.GetKey(). As for the camera, I wouldn't bother parenting it to your player, for 2D platformers I make a seperate script for the camera and have something like transform.position = new Vector 3(GameObject.FindGameObjectWithTag("Player").transform.position.x, yOffset, zOffset); oh i really apreciate your help man.tnx alot. the camera code works awsome.and its ok now ;) about the input part , ive tried it befor but it doesnt work well.when i change it to input.getkeydown() its ok when im moving to the right direction.but if i hold the left arrow it wont work and it moves in wrong direction.getkey is better i think ;) but about the first part.i mean the reason of speeding up when i move to the left direction,im sorry i couldnt get what u mean.u mean that i shoud remove that transform.translate section? but it doesnt work.if u can tell me what to do and help me, i really apreciate it ;) thats the only problem left now . tnx again and forgive me for my bad english ! :)
Aug 11 '12 at 01:52 PM
shahinexir
yes, you need to remove transform.Translate(Vector3.right ); from your rotation section, so make it look like this--> also you can remove this.gameObject from before your transforms
Aug 11 '12 at 02:02 PM
Brett_MMU
aha , tnx again . changed it and the speed problem is done and it moves smoothly . but in the oposite direction! again a new peoblem :( i mean , when i hold left arrow it rotates but it moves to right!!! but the right one is ok ;)
Aug 11 '12 at 02:43 PM
shahinexir
replace amtToMove = playerSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; with amtToMove = playerSpeed * Input.GetAxisRaw("Horizontal") * Time.deltaTime;
Aug 11 '12 at 02:49 PM
Brett_MMU
still the same problem . . . it does not work too :( doesnt matter man . thank for your help . really used alot ;) ill figure it out some how :(
Aug 11 '12 at 03:04 PM
shahinexir
(comments are locked)
|
