- Home /
Character bounces after changing position
/e 2: The bouncing apparently was caused by overlapping materials/shapes even though they were completely flat and the same height. Thanks to the snapping tool I got rid of the overlaps and now the ball rolls smooth!
Hello :)
I'm currently expanding a little on the Tutorial 1, in which you create a rolling ball game. I've created a "Teleporter". When the ball enters a Trigger zone, the ball's position on the Z plane gets changed. The Ball's X, Y position and rotation all remain unchanged.
After the ball's position gets adjusted via this "Teleporter" he 7 out of 10 times bounces off the ground after continuing to roll a short while or starts to bounce immediately after the position change and I can't figure out why he randomly starts bouncing.
The Y plane is level, it's a flat surface and the same height at both positions.
Any ideas why the bouncing occurs? I have tried minimally adjusting the Y position because I thought perhaps the problem has something to do with friction but no luck with that approach either.
/e: perhaps I should mention that I use the standard gravity, friction etc. settings and the ball enters the "teleporter" usually at a "medium" speed. The ground has no physics material applied to it.
Here's the relevant code if that helps:
else if (other.gameObject.name == "TeleportSouth"){
TeleportToPosition1 ();}
void TeleportToPosition1 (){
float currentpositionx = gameObject.transform.position.x;
float currentpositiony = gameObject.transform.position.y;
Vector3 teleportPosition1 = new Vector3 (currentpositionx, currentpositiony, -50.0f);
rigidbody.position = (teleportPosition1);
rigidbody.rotation = (Quaternion.identity);}
Answer by felixpk · Dec 24, 2013 at 12:28 PM
void OnTriggerEnter(Collider other){
if(other.gameObject.tag.Equals("TeleportSouth")){
TeleportToPosition1();
}
}
void TeleportToPosition1(){
float currPosX = transform.position.x;
float currPosY = transform.posdition.y;
Vector3 telePos1 = new Vector3(currPosX,currPosY-0.5f, -50f);
transform.position = telePos1;
}
This is untested and just slightly adjusted, maybe it works like this. It's a good thing to use Tags instead of Names.
This script requieres to be on the Ball, I don't know where the Script is attached to.
If you don't want the Ball to just pop out on the other Position, you could also use
transform.position = Vector3.Lerp(transform.position,telePos1,5f);
I hope that helps a little bit.
Thanks for the quick reply :) I thought you needed a Quaternion as well for some reason, works without just fine to my surprise.
$$anonymous$$ay I ask why it's better to use tags ins$$anonymous$$d of names? Performance reasons or just convenience? I want to avoid - if possible - having a very long list with tags of which some might be even only used once for unique stuff like this teleporters (different teleporter = different target co-ordinates).
The bouncing apparently was caused by overlapping materials/shapes even though they were completely flat and the same height. Thanks to the snapping tool I got rid of the overlaps and now the ball rolls smooth!
$$anonymous$$erry X-$$anonymous$$as everyone!
Honestly I have no clue, but that was something else posted to me. But I think it is convenience.
Ins$$anonymous$$d of having lot of different Teleport tags you could use just one "Teleporter" tag, every teleporter gets that tag. I don't know how the destination of each Teleporter changes but if it's everytime -50 Units backwards, that would be a solution.
Else you could check where the teleporter is, and then decide where to teleport the ball. But that would do nothing special to your game. Just saying.
$$anonymous$$erry X-$$anonymous$$as too :)
Your answer
Follow this Question
Related Questions
how to change physics material of a colider in runtime 5 Answers
Is there anyway to "speed up" physics? 1 Answer
How to make objects "Bounceable" 1 Answer
How to get a perfect bouncing ball. 6 Answers
Swipe Wind 2 Answers