I don’t understand why this is happening. An explanation would help greatly.
I have two objects, Player and Player2. I wrote some code to move these objects. They both have capsule colliders and rigidbodies. Player2 is an exact copy of Player except I set the capsule collider center y position to 1 instead of 0.
To move the objects, I do the following code:
float movemax = 8;
//Get current touch position, check distance from start touch position.
//Update start position if cur touch is too far from it.
if(t.position.x - movecenter.x > movefromcenter){
movecenter.x = t.position.x - movefromcenter;
}
if(t.position.x - movecenter.x < -movefromcenter){
movecenter.x = t.position.x + movefromcenter;
}
if(t.position.y - movecenter.y > movefromcenter){
movecenter.y = t.position.y - movefromcenter;
}
if(t.position.y - movecenter.y < -movefromcenter){
movecenter.y = t.position.y + movefromcenter;
}
Vector2 moveamount = new Vector2((t.position.x - movecenter.x)/movefromcenter, (t.position.y - movecenter.y)/movefromcenter);
//Apply Velocity to both Players based on distance from touch start and touch cur
Player.rigidbody.velocity = new Vector3(movemax * moveamount.x,Player.rigidbody.velocity.y,movemax * moveamount.y);
Player2.rigidbody.velocity = new Vector3(movemax * moveamount.x,Player2.rigidbody.velocity.y,movemax * moveamount.y);
When both objects have the same collider position, they both move in unison. However, when I change the position of Player2’s collider center.y to 1, it moves slower, and when I set it to -1, it moves faster.
If I’m not clear enough in my description, I can supply screenshots.
My question here is: why does the object move differently if I adjust the collider’s position?