Hello,
I made a 3D player with a capsule collider, a rigidbody, an animator and a playercontrol script. I also a moving platform.
The problem I am facing is, the player does not stay on the moving platform. However, when i deactive my player script, the player stays on the platform.
Is player script affecting the player’s physics without being called…?
Any ideas of this problem? Here is my script.
public float runSpeed = 6f;
public float jumpHeight = 8f;
Rigidbody rb;
Animator anim;
bool facingRight;
float distToGround;
void Start()
{
rb = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
facingRight = true;
}
void FixedUpdate()
{
float move = Input.GetAxis("Horizontal");
if (move != 0f) anim.SetBool("isRunning", true);
else if (move == 0f) anim.SetBool("isRunning", false);
rb.velocity = new Vector3(move * runSpeed, rb.velocity.y, 0);
if (Input.GetButton("Jump"))
{
anim.SetTrigger("isJumping");
rb.velocity = new Vector3(rb.velocity.x, jumpHeight, 0);
}
if (move > 0 && !facingRight) Flip();
else if (move < 0 && facingRight) Flip();
}
bool isGrounded() { return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f); }
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.z *= -1;
transform.localScale = theScale;
}
}