- Home /
Movement Help
Hello, I'm been trying to create a action game like movement.
So far I big doing a lot research on this, like from and so on. The way it look like to me that when you hit W your character move up and it rotation you up when you hit S it rotation the character down so he facing the camera and move down. The A and D key make the character turn that way and move that way. I script this and it worker good. the error come from when I'm trying to make the 45 angle one. like WD, WA, SA, SD, I can't come up with how the player slower rotation to that point.
By the way I'm using transform.eulerAngles to rotation the character and before that it check if( transform.eulerAngles.y != 90){ change transform.eulerAngles.y to 90;
PLZ HELP
Answer by mateo4632 · Feb 07, 2016 at 06:22 PM
I am working on a top down type of game to and I have the script for the player movement.
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public float Speed = 15;
public float RotSpeed = 180;
void FixedUpdate()
{
//ROTATING
Quaternion rot = transform.rotation;
float z = rot.eulerAngles.z;
z -= Input.GetAxis ("Horizontal") * RotSpeed * Time.deltaTime;
rot = Quaternion.Euler (0, 0, z);
transform.rotation = rot;
//MOVING
Vector3 pos = transform.position;
Vector3 velocity = new Vector3(0, Input.GetAxis ("Vertical") * Speed * Time.deltaTime, 0);
pos += rot * velocity;
transform.position = pos;
}
}
Just add this to what you want to move and it should work. Let me know if this worked for you!
I try the script. Thank you by the way but it not what I'm looking for, the one that I need is one that when you hit the A key it turn the player left and then move the player in that way. but thank you for the help.
@Gameart1235 so your looking for a grid type of movement? for example W key moves the player up and S moves him down, and then A turns the player 90 degrees counter clockwise and walks left, then D moves turns the player 90 degrees clockwise and moves to the right?
no, more like a action game. but I think I came up with something just need to do more research for it.
Answer by SUpersindit2 · Feb 07, 2016 at 05:23 AM
I would assume that you want smoothing involved, consider using Mathf.SmoothDamp
Your answer
Follow this Question
Related Questions
Character rotates left and right instead of going forward. 1 Answer
Slowly move a GameObject on 1 axis, then destroy it. 1 Answer
New to Unity & Scripting, How Do I Create a Movement System Thats About Building Up Speed? 0 Answers
How to I put a speed limit on my character's movement? 1 Answer
Implementing Counter-Movement 0 Answers