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 / How to fire bullets using physics?

Author
Message
Zigi
15
Years of Service
User Offline
Joined: 5th Jul 2009
Location:
Posted: 12th Nov 2017 20:45
Hi.

The question I'm asking already have been asked several times on the forum but no working solution offered anywhere which is a bit frustrating as we are talking about the basics here in a tool supposed to make game development easy.

So what I would like to do is simply fire bullets toward the angle of the bullet not only in one direction but any direction the bullet is facing and I would like to do it by using physics.
In a perfect world, the only thing I supposed to do is:

1. Create bullet
2. Set angle of bullet
3. Apply physics on bullet
4. Apply impulse on bullet toward the angle of bullet

Job done.

But it seems to be not that simple in AppGameKit at least I can't get it to work
My bullets are flying all over the place and spinning around in all possible directions except the one I would like to, none of my attempts was behaving anything like a bullet and I'm completely lost.
Could anyone help me with some ideas, solutions or may even code snippets to setup a bullet in AKG using physics?

I know I could do it without physics by storing all my bullets inside an array and keep calculating the angle of movement with trigonometry and update the x and y position for each bullet manually but I'm really would like to know if it possible to do it with physics in AppGameKit and how because it is supposed to be the easy way and I can't believe it is so difficult in AGK. There must be something I'm missing. Maybe I should set some global force or something, I'm not sure. I have set gravity to 0 but it is just made my bullets floating in space and when I apply any force on the bullets they start spinning and moving all over the place but never straight ahead.

I would appreciate any help.
Thank you
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Nov 2017 21:38 Edited at: 12th Nov 2017 21:39
i think the most necessary are
SetPhysicsCCD( mode )
SetSpritePhysicsIsBullet
SetSpritePhysicsCanRotate
SetSpritePhysicsImpulse ( iSpriteIndex, x, y, vx, vy )
SetSpritePhysicsIsSensor ( iSpriteIndex, sensor ) //should work as bullet
SetSpritePhysicsAngularImpulse ( iSpriteIndex, impulse )
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.9.3) Radeon R7 265 : Mac mini OS High Sierra (10.13)
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 13th Nov 2017 14:57
here is some gutted code i have used...


Login to post a reply

Server time is: 2024-11-24 05:31:07
Your offset time is: 2024-11-24 05:31:07