Hello,
I am trying to create a treadmill type of platform, so it pushes the player backwards on collision (slow down the player from moving, not to stop him from moving completely).
Any answer or guidance would be greatly appreciated. Thank you
Hello,
I am trying to create a treadmill type of platform, so it pushes the player backwards on collision (slow down the player from moving, not to stop him from moving completely).
Any answer or guidance would be greatly appreciated. Thank you
it depends on a few things. is the game 2D or 3D? if 2D theres already a component SurfaceEffector2D that does this for you
if 3D then there are two possible ways, if the effected object has a CharacterController then have the treadmill script apply a CharacterController.Move() in OnCollisionStay, which will be stacking onto your inputscripts call to CharacterController.Move().
last possible way is to use AddForce and likely using ForceMode.Acceleration
Its a 3D game and iām not using a character controller, but I will try the ForceMode.Acceleration.
Thanks
For future reference if someone needs this:
Look into:
And an example of using the OnCollisionEnter is:
void OnCollisionEnter(Collision col)
{
if (col.tag == "Tag to check")
{
//Do things here
}
}
Ok, after some research and help from you guys and other community members I have managed to make a treadmill!
Here is my finished work, as a reference to anyone searching in the future.
This is added to my player controller, must be OnCollisionStay() or else it will push back and then stop.
void OnCollisionStay(Collision col)
{
if (col.gameObject.tag == "Treadmill")
{
rb.AddForce(-transform.forward * 10f, ForceMode.Acceleration);
}
}
Thank you all!