- Home /
Player not able to climb an angle
So I have a game where the player walks back and forth across the screen I need to keep him at a constant force so originally I was moving him using Translate and Time.deltaTime
This allowed him to move across the screen at a constant speed just fine but I then ran into a number of collision issues. he would get stuck in a wall if flung across the screen too fast instead of turning around when he hit it or he would get stuck in other collision.
So I switched to using the physics engine to add force to him and I got him moving at a constant force now but as soon as he hits a ramp he stops. So my question is how can I get him to ignore this incline? I thought putting constant force under and Update function would push him along how I needed but he wont climb up the angle.
Any thoughts? Thanks as always!
Here's snip of the code I'm using...
private var move = (Vector3(1,0,0));
function Update () {
rigidbody.AddForce(move, ForceMode.Impulse);
}
// Hit edge of screen - invert x direction. function OnCollisionEnter (hit : Collision)
{
var bump = hit.gameObject.tag;
//hit wall turn around if( bump == "wallX") { //rotate physically transform.RotateAround(transform.position, Vector3.up, 180); //change direction move = (Vector3(-1,0,0)); rigidbody.AddForce(move, ForceMode.Impulse); Debug.Log("hit"); }
more code and all but this is the code that turns him around.
Another acceptable answer would be to have a way to improve my collision issues when using transform.Translate and Time.deltaTime as this way has been the most accurate way for me to move the player the way I want.
Answer by Earth-O-Matic · Apr 12, 2011 at 05:31 AM
Alright so if any on is interested here's how I solved my issue.
I decided to stick with transform.translate to move the player since it is constant movement that is more predictable. But I changed the collision to capsule as SuperCheese suggested. This keeps the player from getting hung up on other collision in the level.
As for getting hung up on edge zone walls. I simple deactivated the collision on those walls after the player hit it so that he did get knocked back into it it would not turn him around. The wall turns back on after the player hits the opposite wall. This keeps the player from hitting the wrong wall then turning around and getting stuck walking towards it. Thanks for looking!
Answer by Ariel J · Apr 11, 2011 at 06:07 AM
What type of collider are you using? The best for this situation would probably be a capsule with a frozen rotation.
You may want to use the default force mode too.
When you were using translate and deltaTime, were you using a character collider? The character collider is designed for these types of interactions.
Lastly, have a look at how the character motor script handles movement. I'm not too sure where in the script it does it, but I know that it uses translate and Time.deltaTime
-Aj
I'm using a mesh collider I was not using a character collider though with delta time. I'm also not using character motor script this is something I made from scratch to move the player back and forth that turned into a much larger script.
$$anonymous$$y issues with delta time was that if the player got knocked backwards and hit the wall that is supposed to turn it around it would turn the player around and he would become stuck walking against the wall. I fixed that by deactivating the collision after the player collided with the wall. I'll try some of this once I get home tonight.