Player movment: height and straight besides normal xz axis?
Hello,
I 've met the situations:
1 when i move my player in xz-plane, after awhile the y-position starts changing?
2 when i try to move my player in xz-plane and i cross the plane (not along x- or z- axis), i can not move it in straight line forward?
I 'm moving via a script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class bootcontroller : MonoBehaviour {
public Rigidbody rb;
public transform ;
public float speed = 17;
//good test script
Vector3 rotationRight = new Vector3(0, 30, 0);
Vector3 rotationLeft = new Vector3(0, -30, 0);
Vector3 forward = new Vector3(1, 0,0);
Vector3 backward = new Vector3(-1, 0, 0);
void FixedUpdate()
{
if (Input.GetKey("up"))
{
transform.Translate(forward/2 * speed * Time.deltaTime);
}
if (Input.GetKey("down"))
{
transform.Translate(backward/2 * speed * Time.deltaTime);
}
if (Input.GetKey("right"))
{
Quaternion deltaRotationRight = Quaternion.Euler(rotationRight * Time.deltaTime);
rb.MoveRotation(rb.rotation * deltaRotationRight);
}
if (Input.GetKey("left"))
{
Quaternion deltaRotationLeft = Quaternion.Euler(rotationLeft * Time.deltaTime);
rb.MoveRotation(rb.rotation * deltaRotationLeft);
}
}}
Thx, Rob
Answer by privatecontractor · Jan 23 at 12:17 PM
HI @RobSl,
did you try putting constraint on your Rigidbody component? Maybe it's enough?
Hope will do!
Answer by RobSl · Jan 23 at 04:42 PM
Hi privatecontractor,
I tried your solution, but the problem still exists. The strang thing is when i move the player to an y-level of 10 or more, the problem is solved.
Thx for your reply, Rob
Hi @RobSl,
maybe issue is transform.translate used in FixedUpdate() instead of rb.AddForce().
Your answer
Follow this Question
Related Questions
load scene after video ended 2 Answers
Enemy AI: Player attacke when in FOV 0 Answers
Help with simple player movement 0 Answers
Own player controller script let the view wobbles but why? 0 Answers