Jump to content
  • Advertisement
Sign in to follow this  
way2lazy2care

Unity flash collision question

This topic is 3161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hola. Posted this in the web development section, but got no replies. Need an answer to get working on this game. Post: "I'm making a flash game with a lot of movieclips that need to register collisions. I need to know how I can get collisions to register off of just select pieces of visual data, or specify the bounding box for the movieclip some other way. Here's an example of what i mean. I have a turret, and each turret has a ranch, which is a circle around the turret. I want the turret to be a single object, but have the collision only be detected on the turret itself, not the circle. I'd like to just use the built in flash collision detection, but if rewriting collisions isn't out of the question. Just want to know if that's doable easily in flash. PS: Why doesn't flash have a built in Vector2D or Vector3D class?" Link: http://www.gamedev.net/community/forums/topic.asp?topic_id=551131

Share this post


Link to post
Share on other sites
Advertisement
hello

are you working on AS2 or AS3? I am assuming you are working on AS2

first if turrets are always in a circle, why don't you use two circle collision detection?

If you want to check collision detection on pixel level first you need to draw all objects to a bitmapdata. after that you should draw the object that you want to check for collision into another bitmapdata.

after that for each pixel in the second bitmap data you need to if it has > 0 alpha and pixel on the scene also has > 0 alpha. if both is true there is a collision

here is an example, I hope it will help you to understand what am I trying to say. my explanation sucks =)

swf file

I should mention that you will not be able to do much testing using this method. as2 is very slow, and even as3 will not work with high number of objects.

Share this post


Link to post
Share on other sites
there is no vector class in as2 and as3 (as far as I know, I didn't use as3 that much) but there is a point class but it is not that usefull

and it is in 2D. probably macromedia is never intented to make flash work on 3D =)

Share this post


Link to post
Share on other sites
Quote:
Original post by shultays
hello

are you working on AS2 or AS3? I am assuming you are working on AS2

first if turrets are always in a circle, why don't you use two circle collision detection?

If you want to check collision detection on pixel level first you need to draw all objects to a bitmapdata. after that you should draw the object that you want to check for collision into another bitmapdata.

after that for each pixel in the second bitmap data you need to if it has > 0 alpha and pixel on the scene also has > 0 alpha. if both is true there is a collision

here is an example, I hope it will help you to understand what am I trying to say. my explanation sucks =)

swf file

I should mention that you will not be able to do much testing using this method. as2 is very slow, and even as3 will not work with high number of objects.


I'm working in AS3. Circle to Circle would work fine, but I'm guessing I'd have to make my own Collision system then yes?

Share this post


Link to post
Share on other sites
Quote:
Original post by shultays
yes, it won't be that hard if you work on circles. good luck


Alrighty. That will work fine for the most part. Is there a way to get the bounding box for a movieclip (I have a large square movieclip that needs collision detection and a circle wouldn't work for this one) so I can do circle/square collision?

I think the way AS3 does it is just getting the bounds of the visible movieclip to make a bounding box anyways. Is there a way to get that bounding box so I might be able to do a mix of both?

Share this post


Link to post
Share on other sites
Heya, here's a crash course on circle and box collision

Circle vs Circle test:

1) get distance between the centers of each circle.
2) if the distance is less than the 2 radiuses added together, the circles have collided.

To make it more efficient, you can work with squared distances as appropriate to not have to do the square root operation.

Circle vs Box test (assuming the 2d box is an axis aligned bounding box aka AABB and that this is 2d):


1) Find the closest point on the box to the circle's center by doing the below:
a) X = CircleCenterX
b) if X less than BoxLeft then X = BoxLeft
c) else if X greater than BoxRight then X = BoxRight
d) Y = CircleCenterY
e) if Y less than BoxTop then Y = BoxTop
f) else if Y greater than BoxBottom then Y = BoxBottom
2) Calculate the distance from the closest point on the box to the center of the circle.
3) If the distance is less than the radius of the circle you have a collision.




And hopefully you can figure out box vs box test (:

Hope this helps!

Share this post


Link to post
Share on other sites
Quote:
Original post by Atrix256
Heya, here's a crash course on circle and box collision

Circle vs Circle test:

1) get distance between the centers of each circle.
2) if the distance is less than the 2 radiuses added together, the circles have collided.

To make it more efficient, you can work with squared distances as appropriate to not have to do the square root operation.

Circle vs Box test (assuming the 2d box is an axis aligned bounding box aka AABB and that this is 2d):

*** Source Snippet Removed ***

And hopefully you can figure out box vs box test (:

Hope this helps!


What do you mean by "To make it more efficient, you can work with squared distances as appropriate to not have to do the square root operation."

Where was the Square root Operation in Circle vs. Circle? or do you mean when you calculate the distance between the two points? sorry, your wording just confused me.

Share this post


Link to post
Share on other sites
yeah you got it...

for instance if you wanted to know if a point was inside a circle, you would do something like this...

Distance = sqrt(square(PointX-CircleX)+square(PointY-CircleY));

then if the radius was 10, you would say...

if(Distance < 10) there is a collision!

but if you "square both sides of the equation" you get this...

Distance = (square(PointX-CircleX)+square(PointY-CircleY));

if(Distance < 100) there is a collision!

it saves you the square root operation, which is nice.

if this is weird to you, get it working first with the square root in there, and then if you want to, you can optimize your test by getting it working without the square root.

Share this post


Link to post
Share on other sites
DisplayObject.getBounds(DisplayObject.stage) will get you the bounding box of the display object relative to the stage.

If you want rectangle to rectangle, use (NOTE: these are example variables) myBoundingBox.intersects(otherBoundingBox) to find whether they are intersecting.

Even better, you could skip a step and use DisplayObject.hitTestObject(obj:DisplayObject) to find whether their bounding boxes are intersecting.

If you want to have circle to circle collisions, just have a radius number in each object and do a distance check between each one.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Similar Content

    • By Alexander_Vovk
      Hello Guys!
      Please share your experience, where is it better to find sales manager  specialists for indie team of 6 + people(remotely)?
      Maybe someone has a good experience of cooperation with finding projects through sale managers(USA and Canada)?
      Thank you
      Best Regards
      Alex Vovk
      Co-Founder of Sixteen Squares
      Alexander_Vovk@outlook.com
       
    • By RoKabium Games
      Been a bit quiet recently, but we've been busy bug fixing and tweaking things... Now we have lots more 'Particle effects' in the game, specifically here the Flamethrower and Enemy attacks!
    • By JoshuaFraser
      Hi and thanks for reading, I have an issue with this reactive crosshair script, everything works fine until I start changing the offset. Give the script a go and you will see what I mean, when I do SetOffset(0f); it doesnt always set back to the origional state, if anyone can spot a fix I'd be super appreciative!
      using System.Collections; using System.Collections.Generic; using UnityEngine; public class ReactiveCrosshair : MonoBehaviour { [SerializeField] GameObject c_limb_prefab; private float center_offset = 0f; private float current_offset = 0f; private float max_offset = .5f; private int number_of_limbs = 4; private float limb_length = .05f; private float limb_width = .005f; private List<GameObject> c_limbs = new List<GameObject>(); public void SetupCrosshair(){ for (int i = 0; i < number_of_limbs; i++) { GameObject line_go = (GameObject)Instantiate (c_limb_prefab); line_go.transform.SetParent (this.transform); Vector3 limb_pos = new Vector3 (0f,0f,0f); //line_go.transform.position = limb_pos; line_go.transform.localPosition = limb_pos; LineRenderer line = line_go.GetComponent<LineRenderer>(); line.startWidth = limb_width; line.positionCount = 2; line.SetPosition (0, line_go.transform.localPosition + new Vector3(center_offset, 0f, 0f)); line.SetPosition (1, line_go.transform.localPosition + new Vector3(center_offset + limb_length, 0f, 0f)); line.useWorldSpace = false; c_limbs.Add(line_go.gameObject); } if (c_limbs != null) { OrientLimbs (); SetOffset (0f); } } public void OrientLimbs(){ for (int i = 0; i < c_limbs.Count; i++) { float rotation_step = 360f / (float)c_limbs.Count; c_limbs [i].transform.RotateAround (c_limbs[i].transform.position, c_limbs[i].transform.forward, 90f + (rotation_step * (float)i)); } } public void SetOffset(float _current_spread){ float offset = Mathf.Lerp (0f, max_offset, _current_spread); for (int i = 0; i < number_of_limbs; i++) { if (offset > current_offset) { Vector3 pos = c_limbs [i].transform.position + (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } if (offset < current_offset) { Vector3 pos = c_limbs [i].transform.position - (c_limbs [i].transform.TransformDirection (Vector3.right) * offset); c_limbs [i].transform.position = pos; } } Debug.Log ("SetOffset() offset: " + offset.ToString () + " _current_spread: " + _current_spread.ToString() + " localPos: " + c_limbs[1].transform.localPosition); current_offset = offset; } }  
    • By Erik Nivala
      So, as the title says i am trying to figure out a good way sync all that information with other players in Unity. My problem is that i can't come up with a good solution since i am used to creating classes for everything e.g. attachments are its own class and then the weapon would save a reference to that attachment. But since you can't send custom classes over [Command] & [ClientRPC] i am a little stuck. A solution for this would be giving each attachment for a slot a unique ID and then passing the ID to other player but i feel like that is very error prone if other ppl add a new attachment or the IDs get mixed up.
      Is there a "standard" way that this is usually done that i am missing?
      I am fairly new to programming so any help is appreciated!
    • By MintyLyton
      I'm looking for any team / people that need a programmer for their project. I'm looking to expand my portfolio which you can see Here. I'm more experienced with Unity but I can spend the time to learn new Engines if that's your preference. I have worked on Unreal Engine 4 before but I might take some time to re-learn it, if the project requires it. Feel free to DM here or use the contact info on my website. 
    • By ethancodes
      I'm working on a system for my game that will allow the player to stack pick ups in a queue. As one pick up expires, the next automatically activates. I'm having an issue though where if I pick up the first one, it activates fine, but if i pick up a second directly after it, it overrides the first one, activates the second one, and then once it has run it's course, everything goes back to normal gameplay, no first pick up. I'm not sure why this is happening. Hopefully someone can spot what I'm doing wrong in my code.
      Here is the code for the pick up manager:
      // Update is called once per frame void Update () { if (pickUpQueue.Count != 0 && !pickUpActive) { pickUpActive = true; pickUpQueue[0].ActivatePickUp(); } DeactivatePickUp(); } void DeactivatePickUp () { if (pickUpQueue.Count != 0 && pickUpActive) { Destroy (pickUpQueue [0]); pickUpQueue.RemoveAt (0); pickUpActive = false; } } And here is the PickUp:
      public override void ActivatePickUp () { ball.GetComponent<Ball>().Speed = 2.0f; //increase ball speed... ball.GetComponent<Ball>().StartCoroutine(timer); //...set time that power up is active }  
      There is also a Base Pick Up:
      public void OnCollisionEnter2D (Collision2D collision) { Vector2 tweak = new Vector2 (Random.Range(0f, 0.2f),Random.Range(0f, 0.2f)); this.gameObject.GetComponent<Rigidbody2D>().velocity += tweak; //if the pickup makes contact with the paddle or ball.... if (collision.gameObject.tag == "Paddle" || collision.gameObject.tag == "Ball") { GameObject.FindObjectOfType<GameManager>().GetComponent<PickUpManager>().pickUpQueue.Add(this); Destroy(gameObject); //...and finally destroy power up object } } As a side note, I am trying to find a solution to this that will work for all of my pickups. Some pickups are ammo based, some are timed. 
    • By D34DPOOL
      Edit Your Profile D34DPOOL 0 Threads 0 Updates 0 Messages Network Mod DB GameFront Sign Out Add jobEdit jobDeleteC# Programmer for a Unity FPS at Anywhere   Programmers located Anywhere.
      Posted by D34DPOOL on May 20th, 2018
      Hello, my name is Mason, and I've been working on a Quake style arena shooter about destroying boxes on and off for about a year now. I have a proof of concept with all of the basic features, but as an artist with little programming skill I've reached the end of my abilities as a programmer haha. I need someone to help fix bugs, optomize code, and to implent new features into the game. As a programmer you will have creative freedom to suggest new features and modes to add into the game if you choose to, I'm usually very open to suggestions :).
      What is required:
      Skill using C#
      Experience with Unity
      Experience using UNET (since it is a multiplayer game), or the effort and ability to learn it
      Compensation:
      Since the game currently has no funding, we can split whatever revenue the game makes in the future. However if you would perfer I can create 2D and/or 3D assets for whatever you need in return for your time and work.
      It's a very open and chill enviornment, where you'll have relative creative freedom. I hope you are interested in joining the team, and have a good day!
       
      To apply email me at mangemason@yahoo.com
    • By davejones
      Is there a way to automatically change the start position of an animation? I have a bunch of animations set up on 3D models in unity. The issue is that I need to move the 3D models, however when I do so the animation start positions are not updated and I have to do it manually.

      Changing the transform of key frames is time consuming with the amount of animations I have, so I was wondering if there was a way to do it automatically?
    • By MoreLion
      hey all! We are looking for members for our Unity horror game! 
      Here’s the story:
      After a deadly virus plunges the world into chaos killing 85% of the human population there are now what they call “zones” these zones are watched very closely by the surviving government, people are checked every day for the virus, even if you touch the spit or any human waste or fluids of the victim who is infected, you will die. But one day, people in the west zone start to go missing, 1 woman goes outside the walls to uncover the mystery, is there more to the virus than meets the eye?, That is where your story starts.
      This game is not a long development game, I have loads other game ideas,
      I will also allow you to have a bit of creative freedom if you wish to add or share a idea!
      And no, it’s not a zombie game lol I feel like zombie games are too generic, in this game you will encounter terrifying beasts!
      There is some concept art one of our concept artists have made
      If interested email liondude12@gmail.com
    • By Canadian Map Makers
      GOVERNOR is a modernized version of the highly popular series of “Caesar” games. Our small team has already developed maps, written specifications, acquired music and performed the historical research needed to create a good base for the programming part of the project.

      Our ultimate goal is to create a world class multi-level strategic city building game, but to start with we would like to create some of the simpler modules to demonstrate proof of concept and graphical elegance.

       

      We would like programmers and graphical artists to come onboard to (initially) create:

      A module where Province wide infrastructure can be built on an interactive 3D map of one of the ancient Roman Provinces.
      A module where city infrastructure can be built on a real 3D interactive landscape.
      For both parts, geographically and historically accurate base maps will be prepared by our team cartographer. Graphics development will be using Blender. The game engine will be Unity.

       

      More information, and examples of the work carried out so far can be found at http://playgovernor.com/ (most of the interesting content is under the Encyclopedia tab).

       

      This project represents a good opportunity for upcoming programmers and 3D modeling artists to develop something for their portfolios in a relatively short time span, working closely with one of Canada’s leading cartographers. There is also the possibility of being involved in this project to the point of a finished game and commercial success! Above all, this is a fun project to work on.

       

      Best regards,

      Steve Chapman (Canadian Map Makers)

       
  • Advertisement
  • Popular Now

  • Forum Statistics

    • Total Topics
      631399
    • Total Posts
      2999857
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!