- Home /
Character falls through platform when moving with the mouse
Hello,
I'm taking my first steps with Unity and have got a basic 2D auto-running platformer going. My problem is that I've created a platform that the player needs to move with the mouse (or touch screen) to link two sections of ground so the character can safely run across.
This works fine if you move the platform before the character gets there, but if you move the platform too quickly when the character is already on it, they will fall through the bottom of it. Moving the platform slowly will work though.
How can I match the character's y-axis speed to the speed of the platform when moving it with the mouse?
Could you give us more info about your setup? What components do your player and platform have attached to them? is there a rigidbody
attached to your platform? if so, is$$anonymous$$inematic
should be checked eli$$anonymous$$ating all physics interaction between your player and the platform. Not sure why would you want to match y speeds...
player has capsule collider and rigidbody, platform has box collider and rigidbody. If I check is$$anonymous$$inematic the player launches into the air when you select the platform with the mouse.
I thought matching the y speed would ensure that the player stayed attached to the platform regardless of how quickly the player moved it?
is the platform moving vertically? - if it was horizontally then I guess you meant x ins$$anonymous$$d of y, unless your scene is setup so that the global y is aligned horizontally.
It depends on how you are doing it. I would recommend using a Character Controller over a rigidbody for your PC. It also will matter on how you are moving your transform.
Answer by YJack · Sep 16, 2013 at 05:10 PM
So, your problem is that you are taking off the ground from your player character (or that's how Unity are understanding this). I'm not sure if you can solve this by simple change the Collision Detection parameter from your rigidbody. Probably you will need a more severe solution.
Try some adjustment with you colliders before try the solution below.
If you put your character parented to your plarform when the player try to move your platform with the player over it... well... maybe this can solve your problem.
To do this use: transform.parent = (your platform transform)
The code I have currently for dragging the platform is:
function On$$anonymous$$ouseDown () {
can$$anonymous$$ove = true;
myTransform.Translate(Vector3.up*addHeightWhenClicked);
gravitySetting = myRigidbody.useGravity;
freezeRotationSetting = myRigidbody.freezeRotation;
myRigidbody.useGravity = false;
myRigidbody.freezeRotation = freezeRotationOnDrag;
yPos = myTransform.position.y;
}
While to parent the player to the platform I have this:
function OnCollisionStay (hit : Collision) {
if(hit.gameObject.tag == "platform"){
transform.parent = transform;
}else{
transform.parent = null;
}
}
$$anonymous$$y player character only falls through the platform when it is dragged quickly, otherwise it's fine :\
Whats the point of creating the variable for rigidbody.useGravity if youre not using it?
You have
gravitySetting = rigidbody.useGravity; rigidbody.useGravity = false;
And why parent the player to the platform?
Also, keep in $$anonymous$$d your last response is not an answer.
Your answer
![](https://koobas.hobune.stream/wayback/20220613114259im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why do my triggers not work when I build my game? 0 Answers
String segment comparator 1 Answer
2 Programming Languages 4 Answers
How to make a button go through Gameobjects one at a time.? 0 Answers
Replace A Component Then Crashes 0 Answers