Search Unity

How give jump withot rigidbody and by using translate?

Discussion in 'Physics' started by aksh2143, Oct 29, 2015.

?

Is that possible?

  1. Yes

    1 vote(s)
    100.0%
  2. No

    0 vote(s)
    0.0%
  3. Maybe (if than suggestion please)

    0 vote(s)
    0.0%
  1. aksh2143

    aksh2143

    Joined:
    Jul 6, 2015
    Posts:
    10
    I'm making a game where, when my game object collides with Right or Left wall, it gets jump effect. For that i am using rigidbody.addforce but problem is, when it collides with that wall while falling down, the physics engine also calculte its velocity so the effect of jump just doesn't work there. So i guess i have to remove rigidbody and work everything with transforms. But i don't really know how to do that. Any one out there? Here is my script.



    public class MainScript : MonoBehaviour {

    public GameObject Ninja;
    public bool pingpong;

    Vector3 velocity;
    public float speed, jumpforce , forcefactor;
    float clickforce;

    void Start()
    {
    pingpong = true;
    velocity = Vector3.right;
    }

    void Update ()
    {
    if (pingpong)
    {
    velocity = Vector3.left;
    } else
    {
    velocity = Vector3.right;
    }

    if (Input.GetMouseButtonDown (0))
    {
    if(pingpong){

    Ninja.rigidbody.AddForce(new Vector3(jumpforce,jumpforce,0));
    }else{
    Ninja.rigidbody.AddForce(new Vector3(-jumpforce, jumpforce,0));
    }
    }
    }

    void OnCollisionEnter(Collision collision)
    {

    if (collision.collider.CompareTag ("Rwall"))
    {
    Ninja.rigidbody.AddForce(new Vector3(-jumpforce,jumpforce,0));
    pingpong = false;
    } else if (collision.collider.CompareTag ("Lwall"))
    {
    Ninja.rigidbody.AddForce(new Vector3(jumpforce,jumpforce,0));
    pingpong = true;
    }
    }
    }
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    You should use rigidbody, because it's physic based, but if you really don't like that, then store the yspeed in a variable(it needs to be really small) then in update translate the object up with this speed and remove some from it