Answer the question
In order to leave comments, you need to log in
How to unbind frame rate dependency for Rigidbody.AddRelativeForce?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rocket : MonoBehaviour
{
Rigidbody rigidB;
AudioSource audioSource;
[SerializeField] float rotSpeed = 100.2f;
[SerializeField] float flySpeed = 100.2f;
// Start is called before the first frame update
void Start()
{
rigidB = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
Launch();
Rotation();
}
void Launch()
{
float flyingSpeed = flySpeed * Time.deltaTime;
if (Input.GetKey(KeyCode.Space))
{
rigidB.AddRelativeForce(Vector3.up * flyingSpeed );
if (audioSource.isPlaying == false)
{
audioSource.Play();
}
}
else
{
audioSource.Pause();
}
}
void Rotation()
{
float rotationSpeed = rotSpeed * Time.deltaTime;
rigidB.freezeRotation = true;
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward*rotationSpeed);
}
if (Input.GetKey(KeyCode.D))
{
transform.Rotate(-Vector3.forward*rotationSpeed);
print("rigth");
}
rigidB.freezeRotation = false;
}
}
Answer the question
In order to leave comments, you need to log in
have you tried fixedupdate?
When you press the spacebar, the force vector does not depend on update, but after the first tick, processing is already underway without considering deltaTime (the script ends and the next position is calculated by the engine in normal mode)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question