- Home /
How To Stop Movement With RigidBody.AddForce
So, I'm in the process of making a pinball type game, but the plunger, or spring (or thing that makes ball go), keeps moving after running through a teleportTarget trigger. Make long story short, I need to find a way to either create a force to stop the constant moving of the plunger, or create a negative force to stop it in its tracks (Plunger Script and trigger script below)
Plunger
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SpringScript : MonoBehaviour
 {
     public float springPush = 5000f;
     public Rigidbody rb;
 
     void FixedUpdate()
     {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             rb.AddForce(0, 0, springPush * Time.deltaTime);
         }
     }
     **//the problem area**
     void OnCollisionEnter (Collision collsiionInfo)
     {
         if (collsiionInfo.collider.tag == "SpringTrigger")
         {
             
         }
     }
 }
Trigger
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SpringReset : MonoBehaviour
 {
     public Transform teleportTarget;
     public GameObject spring;
 
     void OnTriggerEnter(Collider other)
     {
         spring.transform.position = teleportTarget.transform.position;
     }
 
 }
Answer by Aeneas_Ferguson · Jan 20, 2021 at 09:01 PM
When you call rb.AddForce, you are continuously adding force because it is in FIxedUpdate(). If you only want to add force once, make a private function to do so. Hope this helps.
Doesn't really answer the question. And you probably meant: to call a function once, call it either in the start or awake etc.
Answer by Llama_w_2Ls · Jan 20, 2021 at 09:37 PM
If you set the rigidbody.velocity to zero, there is no velocity and so no movement:
 rb.velocity = Vector3.zero;
Your answer
 
 
             Follow this Question
Related Questions
How do i maintain the same speed in the air? 1 Answer
How to move player or character Left right by 14 unit every at button click on mobile 0 Answers
How to move your player or character left or right by 14 unit on button click in mobile 0 Answers
Making a bubble level (not a game but work tool) 1 Answer
How do you turn an empty game object into a NavMeshAgent target? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                