Unity Delta Time and Rigid Body

nananana·2022년 9월 21일
0

Youtube Link

Youtube Link

As always Thankyou Creator

Tested Delta Time. Basically previously my computer updated game so fast I placed move functions in FixedUpdate function.

Delta Time helps stabilize the time frame so I can now place movement into the Update() function.

Rigid Body setting.

Interestingly after this setting

with two game objects and collision resulted in interesting behaviour. I lost control although I scripted one ball such that I could control it's movement.

It seem that the vector calculation was broken for the ball after collision.

Sources suggest I shouldn't use translate function when using rigidBody collision suggesting MovePosition instead. However, other sources state translate can be used with rigid body collision and suggested C# related Unity scripting books.
They provided a link but the link is dead. (at least for me)
The title seem to be
unity-3x-scripting-character-controller-versus-rigidbody
So basically a book tutorial on unity scripting.

After further inspection the reason seemed to be determined.

This is after a simple collision. What is noted is the change in rotation. So the script is working fine but the translate function basically take vectors based off of the orientation of the ball.
So if the ball is rotating the vectors are also rotating resulting in odd movements.
If the movement vector is independent of the gameObject (probably some way to do this exist) we can have collisions and easy control over the ball!


Finished with testing tiles physics and friction.

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

public class Mummmmei : MonoBehaviour
{
    // Update is called once per frame
    void Update()
    {
        Vector3 vec = new Vector3(Input.GetAxisRaw("Horizontal")*Time.deltaTime*3,
                            0,
                            Input.GetAxisRaw("Vertical")*Time.deltaTime*3);
        transform.Translate(vec);

        Debug.Log(vec);

        if(Input.GetButtonDown("Jump")){
            Vector3 jmp = new Vector3(0,1,0);
            transform.Translate(jmp);
        }
    }
}

0개의 댓글