Make an Object Stop Moving Upon Collision
I'm trying to make it so that my PlayerObject (A ball) stops moving after touching the top of a pillar (white blocks that the player will be able to jump on). (I understand that I will need to place another object on top of the pillars where the ball can collide and stop moving as the sides of the pillars count as well in the code). After touching the top of the pillar I want the object to stop all movement and resist this code (which is where I need help) after touching it so it won't continuously be stuck on top so it is able to move around on the pillar before jumping again. I need help on how I should come about this problem, I am unsure whether to use time or not. Here's my playercontroller script.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public GameObject Player;
public float speed;
public Text countText;
public Text winText;
public float jumpHeight = 200f;
public float bounceHeight = 0.25f;
private doorRef door;
private Rigidbody rb;
private int count;
private Vector3 offset;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winText.text = "";
}
void Update()
{
//jumping
RaycastHit hit;
Ray bouncingRay = new Ray(transform.position, Vector3.down);
if (Physics.Raycast(bouncingRay, out hit, bounceHeight))
{
if ((hit.collider.tag == "Ground" || hit.collider.tag == "Block") && Input.GetKeyDown("space") || Input.GetKeyDown(KeyCode.LeftArrow) && Input.GetKeyDown("space") || Input.GetKeyDown(KeyCode.RightArrow) && Input.GetKeyDown("space"))
{
rb.AddForce(Vector3.up * jumpHeight);
}
}
}
question.png
(472.9 kB)
Comment