I've been trying to get my character to move along with my moving platform (like when i jump unto the platform it carries me long with it), but so far have been unable to do so.
I have a character with CharacterController, it has also been tagged by ‘Player’.
My moving platform has a ‘Rigidbody’ attached to it, a 'Configurable Joint’and a ‘Box Collider’. The platform is tagged with ‘JumpPad5’.
This is the script attached to my moving platform:
Can’t you make the player a child to the platform with On trigger stay/exit events? That way the player will move, rotate, etc with the platforms movements AND speed, while still having their own controls.
function OnTriggerStay(other:Collider){
if(other.gameObject.tag == "platform"){
transform.parent = other.transform;
}
}
function OnTriggerExit(other:Collider){
if(other.gameObject.tag == "platform"){
transform.parent = null;
}
}
I’ve been working on this for 2 days and finally found a way so that the character can stay on the platform and then be able to move around and continue to stay on the platform.
The principle is simple you want it so that when you collide with the moving platform that the character changes to kinematic mode and the parent is the collider that way the character moves with the collider.
so something like this:
Now that’s all well and good but now while it’s kinematic and parented it’s unable to move on it’s own and programming extra controls to control it in this state is a pain so what you want is that if you move or jump then the character is no longer kinematic or parented. This is best done in the functions update and fixedupdate because it will be checked every frame. So something like this:
This command basically says if your moving and your parented then the player is no longer kinematic and is no longer parented. Then add in your command for jumping so something similar to this:
This way when you are grounded (on the moving platform) and when you press your jump key or function then the object is no longer kinematic and is no longer parented.
This way while you are in collision with the moving platform you will be kinematic and moving with the platform because it’s your object’s parent. But if you are moving or jumping then you are not moving with the platform and the platform is no longer your parent.
This is the first result I had when searching for the same thing, so if anyone sees this in 2022 or later you can try making a new Physics Material 2D with a friction of 10(approx.) and applying it to the collider(drag and drop on the component) of the moving platform.
There are already multiple answers for this question on the site. Please use the search option for next time. These Answers should get you started. If questions remain after reading those, feel free to post them.
Here is a video that allows you too get multiple objects to stick to a platform while allowing you to interact and manipulate them all you want. - YouTube