yeah, when i move the player the angle that it raycasts changes
this what the intended angle is:
but after moving it changes to this angel, which isn’t intended. should stay the same as above:
here is the code i am using:
using UnityEngine;
using System.Collections;
public class NimiController : MonoBehaviour {
public float Speed;
public float JSpeed;
public float FSpeed;
private Animator Anim;
private CapsuleCollider CCollider;
float PrevY;
bool Jump = true;
bool Jump2 = true;
int JCount;
int JumpCount;
RaycastHit hit;
Ray rayline;
// Use this for initialization
void Awake() {
Anim = GetComponent<Animator>();
}
// Update is called once per frame
void FixedUpdate() {
MovementControl();
}
private void MovementControl(){
//horizontal Code
float h = Input.GetAxis("Horizontal");
Anim.SetFloat("Speed", Mathf.Abs(h));
if (Mathf.Abs(h) > 0.5)
{transform.eulerAngles = new Vector3(transform.eulerAngles.x,Mathf.Round(h) * 90f,transform.eulerAngles.z);}
//Jump Code
float v = Input.GetAxis("Vertical");
float v2 = v;
if (v > 0.5 && JCount < 40) {Anim.SetBool("Jump", true);JCount++;}
else if (Anim.GetBool("Jump") == true && v <= 0.1f) {JCount = 40;v = 0f;}
else{v = 0f;}
//Final Movement
rayline = new Ray(transform.position,transform.position + new Vector3(0f,200f ,0f));
Debug.Log(Physics.Raycast(rayline,out hit,200f,1<<8));
Debug.DrawRay(transform.position,transform.position + new Vector3(0f,200f ,0f));
//Detect Falling
if (PrevY > transform.position.y)
{
Anim.SetBool ("Falling", true);
Anim.SetBool ("Jump", false);
Debug.Log("test");
rigidbody.AddForce(new Vector3(0f, -FSpeed, 0f));
//if (Jump2 && v2 < 0.5f){Jump2 = false;JCount = 0;Debug.Log (JCount);}
}
else if (Anim.GetBool("Jump") == false && Anim.GetBool("Falling") == false)//set Jump so you can Jump again
{
JCount = 0;
//Jump2 = true;
}
else {Anim.SetBool ("Falling", false);}
rigidbody.AddForce(new Vector3(Speed * h , (Mathf.Round(v) * JSpeed), 0f));
PrevY = transform.position.y;
}
}
don’t know how to fix this, look all over before asking. the reason why i haven’t used raycast at all in the code cause i been having these problems. curious on how to fix this.
i did a few test with changing to a sphere and see what happens, same results. so i think its nothing to do with the model. tested in a few directions, angle changes then also.