- Home /
Moving character on a moving ground
I have to move my character player on a moving forward ground (which is actually a flying carpet) but the carpet is moving alone leaving the character to fall , So is there a way to make the character stand still on it. please I am a very beginner user and very weak with scripts , if you can give me a ready code I will be very thankful.
When your character is on the rug, make him a child of it.
1) Has your moving object rigidbody? 2) What is the collider material? Needs some friction.
I would recommend what Lo0Nuhti$$anonymous$$ said.
If your player is a child of the carpet, he will move in the same way. Only problem is, if the carpet rotates 'upside down' or goes up, so will the player.
I wouldn't recommend childing a rigidbody to another rigidbody.
Answer by benandlucy · Jul 13, 2014 at 10:54 PM
You could do what the people above said, but it might make some other problems arise in the future.
What I would do is add a OnCollisionStay function in a script for your player object.Like so:
var myCarpet : GameObject;
function OnCollisionStay (col : Collision) {
if(col.gameObject.name == myCarpet.name){
transform.localPosition.x = myCarpet.transform.position.x;
}
}
Don't forget to add the carpet Object to the myCarpet variable. I don't know how well this will work as I have not tested it, but hopefully it will put you on the right track. :)