Spinning object going through player

As highlighted in this video : https://www.youtube.com/watch?v=qr5ySpRrnLo

I have an issue with the big version of my rotating objects. The small one, rotating at the same speed seem to work perfectly. The big one just goes through the player. I tried using different type of Collision Detection, living them as the default… tried to update the Physics settings but nothing seems to work.

Both the rotating object and my player are moved in FixedUpdate.

Does anyone have any idea as to how to fixe this issue?

Here is my rotating object’s script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spinner : MonoBehaviour
{
    [SerializeField] float spinSpeed;

    void FixedUpdate()
    {
        transform.Rotate
        (
            transform.rotation.x,
            -spinSpeed * Time.deltaTime,
            transform.rotation.z
        );
    }
}

And here is the one for my player:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class Mover : MonoBehaviour
{
    [SerializeField] float moveSpeed = 1;
    Vector2 moveInput;
    Rigidbody myRigidBody;

    void Start()
    {
        myRigidBody = GetComponent<Rigidbody>();
    }

    void FixedUpdate()
    {
        Move();
    }

    void OnMove(InputValue value)
    {
        moveInput = value.Get<Vector2>();
    }

    void Move()
    {
        Vector3 playerVelocity = new Vector3 
        (  
            moveInput.x * moveSpeed * Time.deltaTime, 
            myRigidBody.velocity.y,     
            moveInput.y * moveSpeed * Time.deltaTime
        );

        myRigidBody.velocity = playerVelocity;
    }
}

Hi AssaSquid,

Thank you for the video. That’s really helpful. :slight_smile:

I’m wondering if the issue might be caused by the scale. Try the following:
Increase the mass of the spinner’s Rigidbody significantly. In the video, it is 1.


If that didn’t help:

  1. Create a new game object.
  2. Set its scale to (1, 1, 1).
  3. Make the large spinner game object a child of the new game object.
  4. Set the position of the child to (0, 0, 0).
  5. Move the Spinner script to the parent.
  6. Move the Collider to the parent.
  7. Increase the mass of the large spinner significantly.
  8. Test your game again.

Setting the scale of the game object with the collider to (1, 1, 1) is crucial because the scale might affect how the game object might be treated within the physics simulation. To avoid undesired side effects, it is usually a good idea to keep the scale at (1, 1, 1).


If that didn’t help either, I would suggest not to manipulate the velocity but to call AddRelativeForce on the player’s Rigidbody.


And if that didn’t help either, add the Spinner and the Mover scripts to the script execution order list. See here. The spinner is supposed to come first. The numbers in the list define the order and do not have any other meaning than that. Just make sure that the number for the Spinner is lower than the number for the Mover.


See also:

Hi Nina !

Thank you for your reply and the multiple solutions !

I tried all of them but none worked. But while moving the Player’s collider to a parent object, like you suggested doing for the large spinner, I made it bigger (higher on the Y axis) than the original one I was using.

That actually fixed the issue I was having. It seems like the collider being only half a unit in height was an issue.

Here is the fix : https://youtu.be/FVICHy9mcfo !

Awesome! Good job on solving the problem! :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms