Hello guys. I seem to be in a pickle. I’ve reading through the scripting reference and browsing through several coding tutorials. I fibally decided to practice what Have learnt by making a simple 2d player movement script.
However, When I try to make my character jump, he doesn’t. I’m using the ray casting for this.
So I then decided to call the Debug.DrawLine method but that inst working and showing up when I enter play mode. This is a problem since the console doesn’t show any of errors in my code.
So can someone please look trough this and tell me what’s wrong?
using UnityEngine;
using System.Collections;
public class Player_movement : MonoBehaviour
{
public float speed = 15f;
public Vector3 moveDirection;
public Transform jumpEnd;
public bool isGrounded = true;
public float jumpForce = 250f;
// Use this for initialization
void Start ()
{
//Rigidbody2D king = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update ()
{
Debug.DrawLine(this.transform.position, jumpEnd.position,Color.blue);
//Movement ();
//RayCasting ();
}
void Movement()
{
if (Input.GetAxis("Horizontal")>0)
{
moveDirection =(Vector3.left*Time.deltaTime*speed);
transform.Translate(moveDirection);
transform.eulerAngles = new Vector2(0,180);
//transform.localScale = new Vector3(0,0,0);
}
if (Input.GetAxis ("Horizontal") < 0)
{
transform.Translate(Vector3.left*Time.deltaTime*speed);
transform.eulerAngles = new Vector2(0,0);
//transform.localScale = new Vector3(-1,0,0);
}
if (Input.GetKeyDown (KeyCode.Space) isGrounded == true)
{
rigidbody2D.AddForce(Vector2.up * jumpForce);
}
}
void RayCasting()
{
Debug.DrawLine (this.transform.position, jumpEnd.position,Color.blue);
isGrounded = Physics2D.Linecast (this.transform.position, jumpEnd.position, 1 << LayerMask.NameToLayer ("ground"));
}
void FixedUpdate()
{
Movement ();
//RayCasting ();
}
}
the code is a bit messed up since I’ve tried different solutions.