- Home /
Affecting FPS controller/Character Motor physics with game object
Hi
Thanks for taking the time to check my question. Im making an FPS shooter (for a uni project).
Objective: When running into a particular game object, I want to trigger a launch which sends my player into the sky, whilst continuing forwards in the direction of travel and landing back on the ground a distance ahead of the original position, kind of like a catapult or a gravity lift i guess.
Attempts: I have looked at the lerpz tutorial and understand how that work with that controller, but i cant figure out the character motor.
I have the below script working on a rigid body, e.g. bullets, but its not affecting the player, because its not a rigidbody. I have tried putting a rigidbody on the player and turning off gravity, but still no affect.
Can anyone tell me about controller collider? This might be an option but im not quite sure how to work it! Or how to link with character motor.
Please help if you can? Many Thanks Nick
//----jumppad.js----
var jumpAngle:Vector3;
var jumpMagnitude:float=1.0;
function OnTriggerEnter (entity: Collider)
{
//Make sure the triggering entity has a rigidbody before we try to access it!
if(entity.rigidbody)
{
print("hit the booster");
//Apply the force
entity.rigidbody.AddForce(jumpAngle*jumpMagnitude);
}
}
function OnDrawGizmosSelected()
{
//Draw a gizmo in the editor to visualise the jump anglec
Gizmos.color = Color.red;
Gizmos.DrawRay (transform.position, jumpAngle*jumpMagnitude);
}
Answer by Bunny83 · Feb 07, 2012 at 03:58 PM
The problem is that the CharacterController comes with it's own movement calculations. No physics are involved here. The CharacterController is meant for objects that shouldn't be affected by other objects so you have a nice movement control of your player. However, you can of course add this "jump acceleration" manually. I don't use the CharacterMotor scripts that comes with Unity so i can't tell you where you have to add it, but it should also have some kind of velocity (in most examples it was called moveDirection
).
If you want the player to be a real physics object, don't use the CharacterController and switch over to a rigidbody. You should think twice before you decide. The movement has to be handled differently so you can use the CharacterMotor script.
There are some scripts to control a rigidbody in the UnifyCommunity Wiki.
edit
You should read the CharacterController manual to understand what it was made for. If you want direct control of the player you should keep the CharacterController and just add the jump-pad function.
Wow i have just found some really cool control scripts on there! Im fairly new to this (as you may tell) but not entirely sure why I havent come across unify yet so thanks for the heads up on that, what a great site.
Thanks for your response, our characters do need to be affected by other objects (probably starting with the most ambitious) so I think i may look down the rigidbody route but will also take a closer look at the controller manual too.
Thanks again