- Home /
Too subjective and argumentative
Changing the direction of an object using another object.
So I have a little puzzle/like game I've been working on, that involves you changing the direction of tiles so that it will shoot the balls towards their goals, but I need help getting the tiles to change the direction of the ball. The "direction changers" are hexagons with arrows inside of them. The Issue I'm having is i want the balls to be able to enter the hex along the red lines, go to the center of the tile, then exit out of the tile from the green line.
so the ball code is called "Sprite" and is posted below.
var SpriteColor : int;
var speed : float = 1;
function Start ()
{
SpriteColor = Random.Range(1, 13);
//make it check to see what colors of hexes there are and only use those colors??
}
function Update ()
{
//Code to change sprite colors has been removed to shorten this script up a bit.
transform.Translate(Vector3(-1, 0, 0) * speed * Time.deltaTime);
}
function OnBecameInvisible()
{
Destroy (gameObject);
}
and here is my ArrowScript which controls the rotation and various other things within the hextiles.
var TileState : int;
static var TileRotation : int;
var EdgeTile : boolean = false;
var HexArrow : GameObject;
var Arrow : GameObject;
function Start ()
{
TileState = Random.Range(0, 10);
TileRotation = Random.Range(1, 6);
Rotate();
}
function Awake()
{
spriteDir = GetComponent(Sprite);
}
function Update ()
{
if(TileState == 1 || TileState == 10 && EdgeTile == false)
{
FixedTile();
}
}
function FixedTile()
{
//makes this tile unable to be rotated by user Input.
HexArrow.gameObject.SetActive(false);
Arrow.gameObject.SetActive(true);
}
//my failed attempt at trying to work something out with getting the sprite/ball to change direction when it entered the hex tile.
var spriteDir : Sprite;
var DirX : float;
var DirY : float;
function OnCollisionEnter(collision : Collision)
{
if(gameObject.tag == "Ball")
{
transform.Translate(Vector3(DirX, DirY, 0));
}
}
function Rotate()
{
//Randomly rotates the tiles facing a random direction in intervals of 60 degrees at the start of a game.
if(TileRotation == 1)
{
transform.Rotate(Vector3(0, 0, 0));
}
if(TileRotation == 2)
{
transform.Rotate(Vector3(0, 0, 60));
}
if(TileRotation == 3)
{
transform.Rotate(Vector3(0, 0, 120));
}
if(TileRotation == 4)
{
transform.Rotate(Vector3(0, 0, 180));
}
if(TileRotation == 5)
{
transform.Rotate(Vector3(0, 0, 240));
}
if(TileRotation == 6)
{
transform.Rotate(Vector3(0, 0, 300));
}
}
what I'm wanting to do, and cannot figure out is how to make the hex tile script change the direction of the ball script according to the tileRotation. Could anyone help me out?
Too subjective, UnityAnswers is for resolving a very specific issue not to start a discussion. The forum is meant for this kind of topics, so post this on the forum. This should never have passed moderation.
@Joyrider he has 26 karma so his question never went into moderation queue.
@Harshad$$anonymous$$ $$anonymous$$y bad ;) Can you close the question?
@EscTheCtrl this question is being closed for being subjective but you can edit the question to provide additional information like any code you have written or something specific then we can re-open this question.