rb2d.addrelativeforce

I want to move my gameobject in the facing direction so i have tried to use AddRelativeForce, but my object does not seems to move at all. I have my speed value to 60, so is not 0. Please help me.

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

public class PlayerMovement : MonoBehaviour
{

public float speed;
public float rotationSpeed;

float horizontal;
float vertical;

Rigidbody2D rb2D;

void Start () 
{
    rb2D = gameObject.GetComponent<Rigidbody2D>();
}

void Update () 
{
    horizontal = Input.GetAxisRaw("Horizontal");
    vertical = Input.GetAxisRaw("Vertical");
}

void FixedUpdate()
{
    rb2D.AddRelativeForce(Vector3.forward * speed);
    transform.Rotate(0.0f, 0.0f, -horizontal * rotationSpeed);
}

}

Yes, I need to access variables inside the foreach loop to use them outside the loop

–

1 Answer

1

If you are using relative force, the amount of force required to move your object is proportionate to the mass of the object your are trying to move. So if your object is super heavy, you need a lot more force than what you have right now.


Try multiplying the speed by 10x or so, just to get it moving.

i had tried it, no movement at all

–

@Captain_Pineapple Thank you for chiming in, I'm struggling to get the information needed from SuperStar. To me, this problem seems like its the result of coming at a bigger picture of work needed, but from a backward perspective. I think if the overall work needed was explained, we could help more fully to find a solution.

–