Question by
AthosBenther · Oct 19, 2016 at 06:28 PM ·
unity 2d
RigidBody2d not respecting parameters
i have this code:
void FixedUpdate()
{
if (_respawn)
{
isMaxSize = false;
Size = 0;
growSpeed = 0.001f;
maxSize = Random.Range(1, 5);
float rndX = (int)Random.Range(-60, 60) * 100;
float rndY = (int)Random.Range(-30, 30) * 100;
Debug.Log("Trying to Respawn with the Max Size of " + maxSize.ToString() + " at positions X = " + rndX.ToString() + " and Y = " + rndY.ToString());
rb.MovePosition(new Vector2(rndX, rndY));
Debug.Log("Real respawn position: X = " + rb.position.x + " Y = " + rb.position.y);
_respawn = false;
}
}
which outputs:
Trying to Respawn with the Max Size of 4 at positions X = 1400 and Y = -800
UnityEngine.Debug:Log(Object)
food:FixedUpdate() (at Assets/Prefabs/food.cs:53)
and
Real respawn position: X = -79.90599 Y = -63.46048
UnityEngine.Debug:Log(Object)
food:FixedUpdate() (at Assets/Prefabs/food.cs:55)
Even if i use float instead of int the results are the same. RigidBody2d is set to Kinematic, zero g and drag.
Am i missing something?
Comment
Additionally, my inicial respawn code was something like
void Respawn()
{
Size = Random.Range(1, 5);
rb.$$anonymous$$ovePosition(new Vector2((int)Random.Range(-60, 60) *100, (int)Random.Range(-30, 30) * 100));
}
which was giving incorrect coordinates and a visual glitch where the food would appear in the old position with the new size before being moved. When I moved the Size statement under the $$anonymous$$ove statement the Food would not move upon respawn
Your answer
Follow this Question
Related Questions
Black screen instead of playing video 0 Answers
loop and instantiate 1 Answer
OntriggerEnter2d not changing Boolean C# 0 Answers
Why can't I export my game to windows? 0 Answers