- Home /
PlayerMovemeny Help with rotation?
Im having trouble on making my player moving to the direction i rotate it but i want the controls to WASD not AROOW KEYS but also to prevent him from falling of the platform he is on! InFO about the game: its a platformer! Problem : Rotatiing player to the direction its pointing but also to change controls!
Script here :
using UnityEngine; using System.Collections;
public class Rotate : MonoBehaviour {
public float RotateSpeed = 30f;
void Update () {
if (Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(-Vector3.up * RotateSpeed * Time.deltaTime);
else if (Input.GetKey(KeyCode.RightArrow))
transform.Rotate(Vector3.up * RotateSpeed * Time.deltaTime);
}
}
Image Here of the gameplay Style :
If This does not give you enough info please reply saying so and ill put a video up on the gameplay and me showing you what i want in the game script
But please make it in #c it helps if not then go on and make a js script for me to understand!
Yes, Thank you for solving one problem out of list i changed leftarrow and rightarrow to A & D but i have no idea how to make that said player go that direction when i do turn that left or right direction
A very simple way to do this is to have a boolean isFacingRight for example (or an integer : -1 for left, +1 for right, whatever) and in the Update function, just check if your character is in the good direction, if not, rotate it and make him move otherwise.
Thank you for that I have wrote it down but I dont know exactly how to type the code but that should solve another question that i had trouble with.
Try something like this : (I didn't test it)
using UnityEngine;
using System.Collections;
public class Rotate : $$anonymous$$onoBehaviour {
public bool isFacingRight = true ;
void Update ()
{
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow))
{
if( isFacingRight )
transform.rotation = Quaternion.LookRotation( Vector3.left ) ;
transform.Translate( transform.forward * Time.deltaTime ) ;
}
else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow))
{
if( !isFacingRight )
transform.rotation = Quaternion.LookRotation( Vector3.right ) ;
transform.Translate( transform.forward * Time.deltaTime ) ;
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220611234419im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why the player is not rotating and moving at the same time ? 0 Answers
Roll a ball camera problem? 1 Answer
Mathf.Lerp working in one direction but not the other 1 Answer
How to change the angle my character falls at 1 Answer
Rotating Player 0 Answers