Hi guys!
I’m having a little trouble to make the player stop when attain being the display limit. I used the code:
if (transform.position.y > 14)
transform.position = new Vector3 (transform.position.y, 14);
But when the player touches the edge of the screen it moves it to as it should, but teleports 10 x too, what is the reason?
thx!
Duugu
October 15, 2015, 1:26am
2
The parameters of Vector3() are x, y or x, y, and z.
Kiwasi
October 15, 2015, 4:10am
3
Using physics? Just put up an invisible collider
1 Like
BenZed
October 15, 2015, 3:22pm
4
Vector3 pos = transform.position;
if (pos.y > 14f) {
pos.y = 14f;
transform.position = pos;
}
1 Like
I’m not using psychic or rigidbody and thanks Ben, work!
But, i added more line to catch the bottom edge too, like this:
Vector3 pos = transform.position;
if (pos.y > 14f)
{
pos.y = 14f;
transform.position = pos;
}
if (pos.y > -15f)
{
pos.y = -15f;
transform.position = pos;
}
But when I start the game, the player teleport y -14. I’ve removed the pos 14 and only left the -15, but this only occurs when a negative value is added. I’m looking for the causes. Thx!
BenZed
October 16, 2015, 4:40pm
6
Is your player parented to something?
The > -15 should probably be < -15
2 Likes
No.
Oh… is really this, thank you XD