If( < closestY)ĬlosestY = ĬlosestGameObject = ansform?. Physics2D.CircleCast(reticlePosition, reticleRadius, Vector2.zero, collisionFilter, enemysAndWallsHitted, 0) įoreach(RaycastHit2D objHitted in enemysAndWallsHitted) RaycastHit2D enemysAndWallsHitted // holds the results of the circle castĬontactFilter2D collisionFilter = new ContactFilter2D() // filter user by the circleCastĬollisionFilter.layerMask = enemysAndWallsLayers Like this: public LayerMask enemysAndWallsLayers īool HasEnemyInFront(Vector2 reticlePosition, float reticleRadius) Then you cast a CircleCast around the reticle to detect all objects there and checks which one has the lowest Y position, meaning the one that is in the front. One way of doing this is offsetting all the colliders to be above the pivot points of their respectivelly gameObjects, like this. Return ansform = null // if does not hit anything, it means that the path is free of walls RaycastHit2D rayHit = Physics2D.Raycast( origin, direction, distance, wallsLayer) Vector2 origin = player.position + (direction.normalized) * reticleRadius įloat distance = direction.magnitude - reticleRadius Vector2 direction = enemy.position - player.position Description: Block wars is a first person shooter where you are on a platform and have to defend against blocks that attack you. public LayerMask wallsLayer īool HasPathFreeOfWalls(Transform player, Transform enemy, float reticleRadius) You can cast a ray from the player position to the enemy position, if it detects a wall in the middle you don't allow them to shoot. Try declaring it as a GameObject and obviously, if you didnt, assign your prefab to it in the inspector endgroup Leggy7. If(Input.GetMouseButton(0) & Time.You could use Raycast methods. begingroup Havent unity right here right now but I would not use Rigidbody to declare an object to instantiate. Transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset) Vector3 difference = (Input.mousePosition) - transform.position įloat rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg When i pick up an object and bump it into the wall, the picked up object moves away from the center of the screen and doesn't recenter itself. Unity 5.0 is the latest Unity 3D Cinemachine for 3rd Person Shooter Games Among all. How can I do it so that I can only pick up one at a time 2: The smaller problem. Start is called before the first frame updateįirePoint = transform.FindChild("FirePoint") If the objects are near each other the character picks up all of them at the same time. Now create a new gameObject in your scene, and modify the bullet you want to instantiate. Public class WeaponScript : MonoBehaviour You instantiate a whole gameObject, with Components such as, transform, SpriteRenderers, Rigidbody, Collider, etc. I hope i explained it so you can understand what i mean. The gun is attached to the player,its always pointing in the direction of the mouse,and once the raycast detects its colliding with the boss layer,it draws a red line (on top of the already drawn blue line). I used a free model blue Sci-Fi type of gun, and I don't know how to make it fire bullets. So far made like 2 levels and I'm currently working on a boss level. I'm currently working on a platform 2D game.
0 Comments
Leave a Reply. |