- Home /
Multiplying something.forward using a variable doesn't actually multiply, but multiplying by a number does.
So I have an instanciation and I set the velocity of the object with this:
plasma_instance.velocity = (shooting_origin.forward * bullspeed_plasma);
And the object does travel forward from the shooting_origin, but no matter how high the bullspeed_plasma (float) is, it still travels with the same speed.
But wait, there's more... When I multiply it by a number:
plasma_instance.velocity = (shooting_origin.forward * 30);
or
plasma_instance.velocity = (shooting_origin.forward * 400);
...then the velocity is different, as expected. So my question is how to multiply it by a variable?
Answer by Jessespike · Aug 21, 2016 at 12:01 PM
If bullspeed_plasma is a public float then the value in the Inspector will overwrite any starting value you may have inside the script.
For example, you put this script on a GameObject.
public class Test : MonoBehaviour {
public float bullspeed_plasma = 1f;
}
and then you decided to change the value in the script, say 100
public float bullspeed_plasma = 100f;
The value will be 1f when you play the game, because 1f was the last value set in the inspector.
I'm only guessing this was the issue, I'm not really sure what's going on from the provided code. You can multiply a forward with a variable, so that's not the issue. Something else is going on. Try adding Debug.Log and see if anything sticks out
print(bullspeed_plasma);
Yup, that was the issue, I never look at variables in the inspector, but now I did and it had a value of 20, but I was also declaring it in the code. Thanks!
Your answer
Follow this Question
Related Questions
Calculate Angular Velocity to Match Remote Position 0 Answers
Move Ball With Same Velocity on Slope 1 Answer
Resume movement of instanced object relative to the original after instantiation. 2 Answers
Rotate Rigidbody Towards Velocity? [3d] 0 Answers
Velocity powered rigidbody on a moving platform without parenting. 3 Answers