- Home /
how to stop colliders in a collision while using kinematic ways instead of physical ways?
Hello everyone! Here I have 3 items, a CharacterController, a Box and a Wall. I let the Controller to hit the Box making it move away using kinematic ways (e.g. directly editing its Transform.position).
But now I have a problem that if the Box hits the Wall after its being hit by the Controller and moving away, it will stay for a while and then rebound away because it can't pass through the Wall.
I know it's natural to stop the Box if I use physical ways in the Box's moving instead of using kinematic ways. So my quesion is how to stop the Box in the collision while using kinematic ways instead of physical ways?
To do it properly you would have to write your own physics system to calculate what would happen if the velocity was applied the way it should be, then apply the result to your cube. Why not just do it "the physical way" in the first place?
because I want the Box to move a certain distance. If I apply the "physical way" in the first place, can u tell me how to make the Box move a certain distance?
well I would do it on trigger enter
collider other kinematic = true; it'll stop exactly at that point and become kinematic
if you need code to be provided tell me
@Fattie yeah, i tried ur method but the Box didn't stop while reaching the destination. $$anonymous$$y code is as follow
#pragma strict
static var controller : CharacterController;
static var cube : Collider;
static var flag : boolean = false;
static var dir : Vector3;
static var destination : Vector3;
function FixedUpdate () {
if(flag == true)
{
cube.rigidbody.AddForce(dir);
print(cube.transform.position);
print(destination);
if(cube.transform.position == destination)
{
print("true");
flag = false;
dir = Vector3.zero;
destination = Vector3.zero;
cube.rigidbody.velocity = Vector3.zero;
}
}
}
As above, I print the Box's position to see where it is. However it didn't enter the inner "if" code-block when the cube.transform.position is clearly equal to the destination
Answer by sdgd · Mar 25, 2013 at 11:56 AM
this is how I'd do it and as soon as object with tag: "you wanna strict to this tag" and will come in by force will stop.
kinematic never listens to forces
if it's anything else that's dragging you need to catch it inside with get component and disable that script and let me know if you need that too
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
void OnTriggerEnter (Collider Other){
Debug.Log("We're in");
if (Other.tag == "you wanna strict to this tag"){
Other.rigidbody.isKinematic = true;
}
}
}
and OFC this has to be on a wall
extend the collider for 0.5 more
ofc don't forget to accept the answer you are most satisfied for your question
do not forget this is not discussion it's Q/A
if you have sub questions you should open new question
you have FAQ on the right
and maybe your next question should be wider Question of what you want to achieve and provide more information and how you are handling the situation.
Your answer
Follow this Question
Related Questions
Can Kinematic Object collide with other Kinematic Object? 1 Answer
Make Character Controller a Box? 2 Answers
Quickly spinning player glitches through walls 2 Answers
Player Object can hang on the collider forever 0 Answers
Character controller collision 2 Answers