Jump to content

A Physics / HiTest Question


Ninjadoodle
 Share

Recommended Posts

Hi @enpu

1 - What would be the best way to tween / animate a lazer at a particular angle in Panda.

I don't really want to use physics if I don't have to - but do you think that would be the easiest option?

Basically I don't want any gravity, just a projectile moving in a direction.

2 -  Since I want to avoid using Physics - I know you've added a HitTest method.

This method will only test two bounding boxes, is that right?

Any way a circle collision could be added to panda?

Thanks heaps :)

 

Link to comment
Share on other sites

@Ninjadoodle

1) This has really nothing to do with physics. Physics is for stuff like gravity, friction, collision etc. What you are looking for is just to move sprite based on speed and angle, which is basic trigonometry:

sprite.position.x += speed * Math.cos(angle);
sprite.position.y += speed * Math.sin(angle);

2) To detect if two circles are overlapping, calculate the distance between them. If it's lower than the radius of the two circles combined, then they are overlapping:

var distance = a.position.distance(b.position);
if (distance < aRadius + bRadius) {
  // Circles overlapping
}

Here is live example for both:

https://www.panda2.io/examples#misc-example1

Link to comment
Share on other sites

Hi @enpu

Thanks heaps for the examples, they are really useful.

I've kinda been confused on whether I should be using basic physics for stuff like this, but this makes complete sense.

I've only made stuff like this in Construct, which has behaviors like Custom Movement - which lets you send an object in a specific direction.

Thank you for pointing me in the right direction :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...