Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Collision using offset and angle not working...

Author
Message
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 16th Dec 2013 16:56 Edited at: 17th Dec 2013 14:52
****SOLVED****

Hello all!

Im having a little trouble with setting up a sprite for collision. Why? Because I have added an X offset and update the angle every render to make the sprite orbit the center of the screen. Problem is, that AppGameKit thinks that the sprite literally is at a specific X and Y value which doesn't change. Therefore traditional collision checking won't work

So I thought that maybe physics was going to help me... nope. haha
I've been messing around with several different methods and I've managed to create the collision "sphere" that I want... Problem is, because the X and Y coordinates aren't changing... The sprite's collision "sphere" isn't moving...
Setting up my moving sprites:

Setting up my "center of screen sprite":

Updating the Moving sprite's position:

Checking for collision:


Here is a picture of what I mean:http://imgur.com/bRI30Es

All help is appreciated!

nope.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 16th Dec 2013 19:01 Edited at: 16th Dec 2013 19:03
hmm, i don't understand really why you change the local offset if the world
is moving.
SetSpriteOffset ( Enemies[Enemies_Random[1].Sprite].Sprite , Enemy_Offset_1 , 0 )

did u use beta 19 yet?

OT
there also exist GetSpriteXByOffset,
u don't need
GetSpriteX ( World ) + GetSpriteWidth ( World ) / 2
the handle is also default in the middle.

AGK 108 B19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 16th Dec 2013 19:12
Quote: "hmm, i don't understand really why you change the local offset if the world
is moving.
SetSpriteOffset ( Enemies[Enemies_Random[1].Sprite].Sprite , Enemy_Offset_1 , 0 )"

Im not setting the offset for the "world" sprite. Only for the Enemies...


Quote: "did u use beta 19 yet?"

I am using build 108.


Quote: "OT
there also exist GetSpriteXByOffset,
u don't need
GetSpriteX ( World ) + GetSpriteWidth ( World ) / 2
the handle is also default in the middle.
"

I wouldn't need to use that, since the World sprite doesnt have an offset assigned to it.

nope.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 17th Dec 2013 11:54
i think your problem was this line because offset.
SetSpriteShapeCircle ( Enemies[i].Sprite , GetSpriteXByOffset ( Enemies[i].Sprite ) , GetSpriteYByOffset ( Enemies[i].Sprite ) , 64 )



AGK 108 B19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 17th Dec 2013 14:51
I tried altering my code to your example, although it did not help. However, I have solved the problem!!! ( http://i.imgur.com/gmw0cYC.jpg )


So here's whats going on. SpritePhysics does not take into account offset points... Which means that if you are constantly changing the offset point your collision sphere will not follow the image on the screen. However, if you turn physics off, change the properties and turn it on again, it updates the position of the collision sphere. I'm sure a lot of you are going to be annoyed by me changing the physics state of a sprite every frame, but it works! And that's all that really matters.


Anyway, here's my code.
The Movement Code and updating the collision sphere (in the do loop):


The Code for setting up the enemy sprites:


The collision code:


This line here
is basically where all the magic happens. You can find it in the "Movement code and updating the collision..." part. The numbers in here can be explained in here:


Hope this helps someone in the future... Took me a while to figure out! Thanks anyway Markus!

nope.

Login to post a reply

Server time is: 2024-11-24 23:54:28
Your offset time is: 2024-11-24 23:54:28