- Home /
How to Implement an 'Icy' slope effect on the FPS Controller
After a little reading it seems that the unity FPS controller does not react to the physic materials. So how would you go about creating the effect of the player sliding down an icy slope ?
???
Unfortunately the standard FPS Controller doesn't contain/use a rigidbody component.
Did you add the physic material to the ground and not on the player? You could do that, or then check when the player is on the icy terrain and everytime you inputs a movement , AddForce that will incrementaly become 0 with $$anonymous$$Athf.Lerp to simulate icy effect. Idea of the top of my head.
Hmm.. was thinking maybe add a rigidbody component to the FPS Controller set it to inactive/disabled. Add the ice physics component to the slope and a collider/trigger.
Then when the player touches the slope have OnTriggerEnter function enable the rigidbody and disable the FPS Controler script.
???
Let me know how it goes , i have no idea if it works :P
Answer by Noah Dyer · Feb 16, 2015 at 08:31 PM
I would probably create "ice" colliders just above the ground in icy areas, and either give them a specific name, tag, or layer. Then in my player OnCollision, I would check if the collider, matched my ice colliders, and there I would simulate ice physics.
Alternatively, you could capture the playerObject from OnCollision on the iceObject, and run the simulation there.
Ok, in theory I've almost solved this.
If you add a rigidbody component and a capsule collider to the 'First Person Controller', then disable the 'Character $$anonymous$$otor Script' your player will be affected by physic objects (in this case Ice)and slides down the slopes perfectly. Even slides a little further than the end of the slope, I'm guessing due to momentum (which is a nice little effect I hadn't planed on)
Once off the slope/Icy surface just re-enable the 'Character $$anonymous$$otor Script', then disable the rigidbody component and capsule collider and you're good to carry on.
So far all this has been done manually in the inspector, so now just need to code some script to do this OnTriggerEnter/OnTriggerExit are activated.
(any help on this part would be appreciated)
Should be something like this, inserted in the player script
//Variables
Character$$anonymous$$otor cm;
CapsuleCollider cc;
//Start function
in Start (){ cm = GetComponent<Character$$anonymous$$otor>();
cc = GetComponent<CapsuleCollider>();}
// The trigger enter function
void OnTriggerEnter(Collider other) {
if (other.tag == ice)
{cm.enabled = false;
cc.enabled = false;
}
}
Regarding the rigidody i suggest you take a look here and figure out what you want exacly cause it gets trickier.
Your answer
Follow this Question
Related Questions
Apply physics material to a third person character? 0 Answers
DragRigidBody: Use mouse instead of camera position 0 Answers
How to create icy floor? c# 1 Answer
Making objects slide 1 Answer