Hey Guys,
First off I want to say that this forum has been incredibly resourceful for a beginner game developer such as myself. I want to say a big thank you to everyone contributing to this community :).
Now for my problem.
I have a game where you play a frog that can move along the x xis and he needs to eat flies. The main mechanic is the the frog’s tongue. I have it set up so that on mouse down (anywhere on the screen) a game object spawns at the frog position and moves towards the Camera.main.ScreenToWorldPoint(Input.mousePosition); with a linerenderer to create the tongue itself. Upon reaching the target position, the game object will move back to the frog position.
Flies spawn on the side of the screen and move along the x axis in a zig zag pattern which is all fine.
After play testing with a few people I found that when you tap a fly the tongue will shoot out and move to the position you tapped. It takes a short time for the tongue to reach that point and by the time it does, the fly is no longer in that position. So the game required you to predict where the fly would go.
So a lot of players found this frustrating and I now believe for the game to be more fun i need to change it so when players tap the fly the tongue should just move towards the fly’s position and not the position of the screen they tapped.
I dont know if I woke up on the wrong side of the bed this morning but when I tried to implement this change after around 3 hours my brain decided to explode and force me to ask for help.
I’ve attempted using ray casts to detect the object being clicked and then move the instatiated tongue object prefab to the hit object, but of course this will only return the position of the hit object when clicked.
Heres a snippet of the code in c#
void Update () {
if(Input.GetMouseButtonDown(0)&&(!shooting)){
Vector3 target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
shooting = true;
GameObject InstanceTongueHitBox = (GameObject) Instantiate(tongueHitBox, transform.position, Quaternion.identity);
GameObject InstanceTargetBox = (GameObject) Instantiate(targetBox, target, Quaternion.identity);
if(hit.collider != null)
{
Debug.Log(hit.collider.gameObject.name);
Debug.Log(hit.collider.transform.position);
LeanTween.moveLocal ( InstanceTongueHitBox, hit.collider.transform.position, 0.25f);
}else{
LeanTween.moveLocal ( InstanceTongueHitBox, target, 0.25f);
}
}
I hope there’s a simple solution to this and i feel like there is, but being a beginner I’ve really got no clue at this point. I would really appreciate some help on this one. Is there a better way to go about this all together?
Thank again guys!
- Jay