Hello there,
I am making a ski game, and i have my graphics in place.
But i can’t get the character controller working so that my character is moving automatic down the slope and steer him.
Can someone help me out ?
Thanx
Hello there,
I am making a ski game, and i have my graphics in place.
But i can’t get the character controller working so that my character is moving automatic down the slope and steer him.
Can someone help me out ?
Thanx
Hi, welcome to the forum!
What exact problems are you having with your CharacterController?
I made an almost vertical slope and i give the slope the icy material and i want my character to descend automatic down the slope on his snowboard/ski. (Building more speed)
I use the character controller from the 3rd person tutorial and when i move the character on the steep slope, it stops and it will not descend.
What must i do to give my player some physics ?
When you call the CharacterController’s Move function (or SimpleMove), add a downward component to the movement vector. If there is something solid under the character, it will not fall through, but it will always fall downward when it is in the air.
How do you mean because i can’t find SimpleMove in the script(just move).
And if i put the donward component there it gives errors.
The CharacterController definitely has both a Move and a SimpleMove function. Which errors are you getting when you try to do this? Can you post the script you are using?
i step off the character controller because i’m using rigidbody.
var speed = 10.0;
var gravity = 10.0;
var maxVelocityChange = 10.0;
var canJump = true;
var jumpHeight = 2.0;
private var grounded = false;
@script RequireComponent(Rigidbody, CapsuleCollider)
function Awake ()
{
rigidbody.freezeRotation = false;
rigidbody.useGravity = false;
}
function FixedUpdate ()
{
if (grounded)
{
var targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
targetVelocity = transform.TransformDirection(targetVelocity);
targetVelocity *= speed;
var velocity = rigidbody.velocity;
var velocityChange = (targetVelocity - velocity);
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
if (canJump Input.GetButton("Jump"))
{
rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
}
}
rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
grounded = false;
}
function OnCollisionStay ()
{
grounded = true;
}
function CalculateJumpVerticalSpeed ()
{
return Mathf.Sqrt(2 * jumpHeight * gravity);
}
that is my code now.
I thought that i must add a rigidbody.velocity.y = -1;
but that didn’t work.
You seem to be using a combination of AddForce and setting the velocity value directly, which might be causing problems. Generally, it is a good idea to add all the velocity or force vectors together and then apply the result in one place. Also, the rigidbody will react to gravity by default, so you don’t need to apply the gravity force yourself (unless there is some special reason why it is necessary here).