- Home /
How do I get my player to jump while the position has been freezed
Hello, I have got this scene where the player jumps on to a rope, then they should stay at that height one they hit the collider and then should be able to jump off again but my code doesnt seem to work?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RopeAttach : MonoBehaviour
{
public GameObject player;
public Rigidbody Rb;
void Start()
{
Rb = GameObject.Find("player").GetComponent<Rigidbody>();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject == player)
{
if (Input.GetKeyDown(KeyCode.Joystick1Button0))
{
Rb.constraints = RigidbodyConstraints.None | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
}
else
{
Rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
}
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject == player)
{
Rb.constraints = RigidbodyConstraints.None | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
}
}
}
Also just this to make the player jump on my PlayerController script:
void Update() {
if (isGrounded) {
if (Input.GetKeyDown(KeyCode.Joystick1Button0)) {
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
2D Rigid Body collisions cause gap 0 Answers
How to make realistic collision? 1 Answer
Unfreeze constraint on enter,freeze on start 1 Answer
climbing the hill? 1 Answer
Can i make more gripped rigidbody sphere Controllers 0 Answers