Work out angle of collisions
imjustmike
Member Posts: 450
If I have a circle actor, and another actor collides with it, is there anyway to work out what the angle is on the circle of the collision?
Hmm, that might not make much sense. More specifically - I have a planet actor (big circle actor), and an asteroid actor. when asteroid collides with the planet, I want to spawn an actor at that point. That's no biggie - but the planet is rotating and I want the spawned actor to rotate with the planet as well, which is where I'm falling down, I can't figure out a way to determine the angle on the circle at the point of the collision.
I don't suppose anyone has attempted anything similar, or can think of a way to work this out?
Comments
So you want to spawn an actor that will orbit the planet at the place of collision?
HA, that is a MUCH simpler way of saying what I'm trying to do, yes.
Hmm, that's a bit of a tricky one. Luckily, there is a tutorial!
Ah, so the orbit around the planet bit isn't the issue per se, thanks to a free (insanely helpful) template from @StormyStudio - it's about working out what angle the spawned actor should orbit to.
So, in my scenario, the planet is rotating and an asteroid collides with it. I want it to spawn a actor that then rotates with the planet at the same speed.
Do you mean detecting the original coordinate of the collision and spawning the orbiting "rock" there?
Why not just spawn it where the asteroid is? Or somewhere close?
It will be . . .
constrain X and Y to:
X . . . . Planet radius * cos ((self.time * planet rotation speed) + vector to angle( self x -planet x, self y -planet y)) + planet x
Y . . . . Planet radius * sin ((self.time * planet rotation speed) + vector to angle( self x -planet x, self y -planet y)) + planet y
. . . hold on, let me throw that into a quick demo project to check . . . .
@imjustmike
Here you go (click anywhere on the screen to spawn an asteroid)
https://www.mediafire.com/?tue5m94ub886791
@Socks That is EXACTLY what I've been trying to do! I'd completely forgotten that the spawn behaviour can just spawn at the location AND I could have separate constrains for the newly spawned actor that would just kick it. Sigh - long day at the office!
Thank you very much
No problem glad it works for you.
The actual maths is pretty simple, when the new orbiting actor is spawned it takes it's angle from its birth time - so it starts life at 0 seconds - so 0 degrees . . . . you just need to add on the angle at which it hit the planet - and that's it really.