Help: Use a Trigger object to slow Player while inside object
Hi there! I want to put a patch of snow on the ground that slows my player (the ball from Roll-A-Ball) while the player is rolling in it. Can anyone held me figure out a script that I can attach to my snow patch that will slow my player while it's inside? I've been messing around with OnTriggerEnter but I have had no luck so far. Thanks in advance!
Why OnTriggerEnter() is not helping you ..
As far I'm thinking you just have to play the sound when player come in the region and stop the sound OnTriggerExit()
.. Can you please elaborate the issue you r facing ..
Sure, thanks for responding! I guess we can start at square one if you have any suggestions. I'd like to add a snow patch that slows the player when the player is within it's collider but I have no idea how to achieve this slowing effect. Any suggestions? I can set the object up with it's materials and collider, but I am unsure what to write in a script in order to slow the player for a brief period of time.
I m not sure with roll a ball character controller, but normally either of the objects colliding need to have non kinematic rigidbody when using OnTrigger. Then you just need to access character controll script and change maximum speed
Okay brilliant! How can I access the player controller script through the snow patch to lower the player's movement speed? or Is it easier to edit the script on the player ins$$anonymous$$d?
void OnTriggerEnter(Collider other) {
if(other.transform.tag == "Player") {
Other.gameObject.GetCompoment<NameOfTheCharacterControllerScript>().nameOfTheSpeedVariable \= SpeedDivider;
}
}
void OnTriggerExit(Collider other) {
if(other.transform.tag == "Player") {
Other.gameObject.GetCompoment<NameOfTheCharacterControllerScript>().nameOfTheSpeedVariable ×= SpeedDivider;
}
}
//also make sure that the speed variable of the character controller is public so it can be accessed
Your answer
Follow this Question
Related Questions
I have problems with scripting movement, anyone can help me? 0 Answers
How to stop movement script on void start and resume after. 0 Answers
Moving walls in multiple places 1 Answer
Rigidbody2D movement is lagging 0 Answers
Touchscreen Question 1 Answer