Question about moving in isometric game
Hi folks!
I'm Unity noob and I'm creating my first game. It's a isometric 3D platform game. I have small problem with my character movement which is a simple block. Whenever I move in the world it moves correctly but my character does not stay facing the direction which I have been moved. Y rotation axis just resets to 0.
I've tried everything but I haven't figured this out. I know that I must store the rotation's y-value, but I don't know how.
My character controller is done by this tutorial: https://www.youtube.com/watch?v=XhliRnzJe5g&t=1s
Answer by randomCreator01 · Oct 25, 2017 at 06:19 PM
Yes here it is:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FluffyMovementISO : MonoBehaviour {
[SerializeField]
public float moveSpeed;
Vector3 eteen;
Vector3 oikealle;
bool hyppy = false;
public float hyppyKorkeus;
public float hyppyNopeus;
Rigidbody rb;
// Use this for initialization
void Start()
{
eteen = Camera.main.transform.forward;
eteen.y = 0;
eteen = Vector3.Normalize(eteen);
oikealle = Quaternion.Euler(new Vector3(0, 90, 0)) * eteen;
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Jump") && !hyppy)
{
StartCoroutine(Jump());
}
else
{
Move();
}
}
void Move()
{
//transform.rotation = Quaternion.Euler(0f, 90, 0f);
//Vector3 direction = new Vector3(Input.GetAxis("HorizontalKey"), 0, Input.GetAxis("VerticalKey"));
Vector3 rightMovement = oikealle * moveSpeed * Time.deltaTime * Input.GetAxis("HorizontalKey");
Vector3 upMovement = eteen * moveSpeed * Time.deltaTime * Input.GetAxis("VerticalKey");
Vector3 heading = Vector3.Normalize(rightMovement + upMovement);
transform.forward = heading;
transform.position += rightMovement;
transform.position += upMovement;
}
IEnumerator Jump()
{
float originalHeight = transform.position.y;
float maxHeight = originalHeight + hyppyKorkeus;
rb.useGravity = false;
hyppy = true;
yield return null;
while (transform.position.y < maxHeight)
{
transform.position += transform.up * Time.deltaTime * hyppyNopeus;
yield return null;
}
while (transform.position.y > originalHeight)
{
transform.position -= transform.up * Time.deltaTime * hyppyNopeus;
yield return null;
}
rb.useGravity = true;
hyppy = false;
yield return null;
}
}
Rotation happens here:
Vector3 heading = Vector3.Normalize(right$$anonymous$$ovement + up$$anonymous$$ovement); transform.forward = heading; transform.position += right$$anonymous$$ovement; transform.position += up$$anonymous$$ovement;
well in both u are changing the position ; should not be some one transform.rotaition;
Your answer
Follow this Question
Related Questions
How can I add movement correction for a 2D platformer? 0 Answers
Detecting missing collision in 2D platformer to change direction for enemy - without Raycast 1 Answer
Can't move while crouched 0 Answers
How can I move my 2D car in 16 fixed angles like in Retro City Rampage 1 Answer
Help! Collision will not work, but all others will 0 Answers