- Home /
Problems with parabolic jump (C#)
Hey everybody, I'm new here in UnityAnswers (also with the software and the programming language C#) and I have some troubles with making a game object that moves the same distance in the X axis, when it's jumping. I want to implement this in a platform game, that when the player press the right arrow it should move and jump to the right and when the player press the left arrow it should move and jump to the left, the problem is that the platforms are higher than the floor so, because of the parabolic movement the object won't go to the same (x,y) position, i will leave the script used right here (I know its a theme of forces in the physics system of Unity). I would really appreciate if someone could help me.
Thanks
SCRIPT:
using UnityEngine; using System.Collections;
public class Jump_And_Move_Script : MonoBehaviour { public float JumpHeight; public float Multiplier; public float Movement; private bool IsJumping = false;
void Update ()
{
if (Input.GetKeyDown (KeyCode.RightArrow))
{
if (IsJumping == false)
{
rigidbody2D.AddForce (Vector2.up JumpHeight Multiplier);
rigidbody2D.AddForce (Vector2.right Movement Multiplier);
IsJumping = true;
}
}
if (Input.GetKeyDown (KeyCode.LeftArrow))
{
if (IsJumping == false)
{
rigidbody2D.AddForce (Vector2.up JumpHeight Multiplier);
rigidbody2D.AddForce (-Vector2.right Movement Multiplier);
IsJumping = true;
}
}
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == "Ground")
{
IsJumping = false;
}
}
}