Question by
masonklaassenn · May 26, 2019 at 06:44 AM ·
movementscript.player movementendless runnertilt
player tilting left or right on key press / while turning left or right?
So i am making a game where the player is always moving upwards on the Y axis and can move left and right. But at the moment he just slides to the left and right but I want that movement to be more smooth. Basically where the object just rotates or tilts side to side depending on which direction you are trying to go.
Here is the current code I have for the movement of my player :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
public float upSpeed;
public float sideSpeed;
private Rigidbody myRigidBody;
// Start is called before the first frame update
void Start()
{
myRigidBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
myRigidBody.velocity = new Vector2(myRigidBody.velocity.x, upSpeed);
if (Input.GetKeyDown(KeyCode.D))
{
myRigidBody.velocity = new Vector2(sideSpeed, 0);
}
if (Input.GetKeyDown(KeyCode.A))
{
myRigidBody.velocity = new Vector2(-sideSpeed, 0);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Transfering script to other game objects via code (Unity 2D) 0 Answers
How to make a turn like the Temple Run and NO THING ? 2 Answers
Moving player with mouse problem Vector3.MoveTowards() 0 Answers
How to stop movement script on void start and resume after. 0 Answers
Moving walls in multiple places 1 Answer