Reputation: 323
Ok, I have a game where the user does not control jumping, rather they just walk the character around using a joystick. I need it to be that when they approach a platform (they walk into the area below it, or are on a platform below it, they will Mario jump onto it.
My approach would be have a box collider for the platform and one as a trigger, so when the user enters the trigger I can iTween them to a position on the platform. Is this the simplest way?
My character's rigidbody has isKinematic and Gravity checked. What is another method to make characters jump when they walk to the position of a higher platform?
Upvotes: 0
Views: 421
Reputation: 565
If you're platforms are always the same height (or not generated at random heights) you can use one or a series of rays.
public float heightOffset;
public float rayDistance;
Vector3 position = transform.position + new Vector3(0f, heighOffset, 0f);
Vector3 rotation = transform.forward;
if(Physics.Raycast(position, rotation, rayDistance))
{
Jump();
}
And repeat that for every heightOffset.
Upvotes: 0
Reputation: 1945
Another method is to raycast down in front of the character to detect the height difference, and if the height difference is within the correct range for the jump, make them do the jump.
But using triggers is ok, too. Depends on the game.
Upvotes: 0