Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

help me how to make weightless

A topic by Kamronus created Jul 07, 2024 Views: 240 Replies: 3
Viewing posts 1 to 5

help me how to make weightless stones in Unity!

I need the objects to stand still and then when they are stepped on they should release down a little and then return to their initial position (like flying stones in movies)<img src="https://img.itch.zone/aW1nLzE2ODMwMjUwLnBuZw==/original/eZkjEE.png">

Moderator moved this topic to General Development
Moderator(+1)

(moved to the right category)

(+1)

You have to add a collider and a rigidbody to your gameobject. Disable "UseGravity" and "IsKinematic". Under constraints set all rotations to freeze.

Attach a script that simulates the physics you want. For example:

public class Bounce : MonoBehaviour
{
    private Vector3 _initialPosition;
    private Rigidbody _rigidbody;
    void Start()
    {
        _initialPosition = gameObject.transform.position;
        _rigidbody = GetComponent<Rigidbody>();
    }
    void Update()
    {
        var force = 50 * (_initialPosition - gameObject.transform.position);
        var damping = -5 * _rigidbody.velocity;
        _rigidbody.AddForce(force + damping, ForceMode.Force);
    }
}
This will apply a force to your object when it is pushed out of position to move it back. The damping is needed to prevent infite oscillation. You have to tune the factors for force and damping to match the weight of your object and the weight/force that pushes your object out of position.

thank you my dear friend very match!