Answer the question
In order to leave comments, you need to log in
How to make a static movement to the side?
Hello everyone, in general, the game is like a flappy bird. It is necessary that the player constantly moves to the side (for the player it is straight), I do it like this
void FixedUpdate(){
rb.AddForce(target.right * 0.06f, ForceMode.Impulse);
}
public void Move(){
if(Energy > 0){
rb.AddForce(target.up * jumpForce,ForceMode.Impulse);
if(!Nimb)Energy--;
}
Answer the question
In order to leave comments, you need to log in
Use normal movement, not via AddForce.
Use Rigidbody's velocity to set a specific speed, not some force.
Here is an example:
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class Bird : MonoBehaviour
{
[SerializeField] private float _speed;
[SerializeField] private float _jumpSpeed;
private Rigidbody2D _rb;
private void Start()
{
_rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
Move();
if (Input.GetKeyDown(KeyCode.Space))
{
Jump();
}
}
private void Jump()
{
var velocity = _rb.velocity;
velocity.y = _jumpSpeed;
_rb.velocity = velocity;
}
private void Move()
{
var velocity = _rb.velocity;
velocity.x = _speed;
_rb.velocity = velocity;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question