My * won't work in a few scenarios im new and don't know what's wrong

using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.Rendering.Universal;
public class PlayerMovement : MonoBehaviour

{
public Rigidbody2D tankRB;
public GameObject player;

public float accelerationFactor = 30f;
public float turnFactor = 3f;

float accelerationInput = 0;
float steeringInput = 0;
float rotationAngle = 0;

public void Awake()
{
    tankRB = GetComponent<Rigidbody2D>();
}

// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
    
}

// Update is called once per frame
void Update()
{
    
}

void FixedUpdate()
{
    ApplyEngineForce();

    ApplySteering();
}

void ApplyEngineForce() 
{
    Vector2 engineForceVector = transform.up * accelerationInput * accelerationFactor;

    tankRB.AddForce(engineForceVector, ForceMode2D.Force);

}

public void ApplySteering() 
{
    rotationAngle -= steeringInput * turnFactor;

    tankRB.MoveRotation(rotationAngle);

}

public void SetInputVector(Vector2 inputVector) 
{ 

    steeringInput = inputVector.y;
}

}

I’ve done a tutorial to help make some code to get my player character to move the right way but in two different cases it hasn’t worked due to my * symbol not multiplying. “rotationAngle -= steeringInput * turnFactor;” is the code thats not working as it should.

another problem I’ve had is when trying to multiply a float by Time.deltaTime.
idk if anyone can help but id appreciate any sort of help i can get and I’m sure its probably a easy solution but I haven’t found it yet

Hello!
I have exactly the same problem. Anyone got a suggestion? This is quiet a common issue

Best Regards,
Erika
StarbucksSecretMenus

I mean in OP’s case, in both instances he’s multiplying with a value that is zero. So the result will always be… zero.

1 Like

You seemingly set the steeringInput value inside your SetInputVector method. However this method is not magically called. It’s probably meant to be called from the new input system. However you have to setup this properly. When you follow a tutorial, you either missed that part or you’re not there yet. Since the method is public, it might be supposed to be called from another script. We can’t tell since we neither know the tutorial nor the context and other scripts you may or may not have.

In any case, like Spiney said, a multiplication certainly does work. You should have checked with some Debug.Logs what parts of your script are actually executed and what values you have at which point. Concluding that a multiplication operator somehow doesn’t work would be equally unreasonable to conclude that unicorns tempered with your RAM…

1 Like