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 / can i shoot a bullet with physics?

Author
Message
haliop_New
User Banned
Posted: 9th Nov 2014 16:42
hi im trying to shoot bullets
for now i have a very simple yet functioning code



move sprite function which i took from the forum



so this works great but what if i want to add physics to a bullet?
how can i "Shoot" a bullet using physics ? can anyone help ?

thank you for your time, haliop.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Nov 2014 18:22
yes should work,
there is a extra flag,
SetSpritePhysicsIsBullet( iSpriteIndex, bullet )
bullet - 1 to set this sprite as a bullet, 0 to turn it off.

u shoot with impulse.
SetSpritePhysicsImpulse( iSpriteIndex, x, y, vx, vy )

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
haliop_New
User Banned
Posted: 9th Nov 2014 20:48
thanks

but what vars i put inside SetSpritePhysicsImpulse?
cause i use an Angle to shoot at . how can i convert the angle to VX,VY ?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Nov 2014 23:33
its the direction (unit vector) *value
u already used
a# = getSpriteAngle(spriteID)
vx#=cos(a#)*value#
vy#=sin(a#)*value#

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
haliop_New
User Banned
Posted: 10th Nov 2014 08:00
thank you
and x,y should be what 0 ? or the position of the first sprite ?
i'll try it out , thank you alot.
haliop_New
User Banned
Posted: 10th Nov 2014 08:06
thanks man i got it working
thank you.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Nov 2014 08:30
The X,Y coordinate of the impulse position in world coordinates.
Means Bullet Pos. at Start.

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
haliop_New
User Banned
Posted: 10th Nov 2014 09:03
yeah i got it after testing however putting 0,0 will give the same effect ..
however
this is what i have


it acts like a bullet but its kinda low on range.. i thought 60,000 would do enough but no matter how big the var is it kinda gives me the same results.
haliop_New
User Banned
Posted: 10th Nov 2014 09:08
btw markus can you share some ideas on how can i learn about sin and cos ?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Nov 2014 10:29
If you know the angle you want to shoot at and the speed you want to shoot at you can get the X and Y values using Cos and Sin.

Cos(angle) = X / speed
so...
X = Cos(angle) * speed

Sin(angle) = Y / speed
so...
Y = Sin(angle) * speed

That's the basics of everything you need to know about Cos and Sin.
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 10th Nov 2014 12:01
Quote: "it acts like a bullet but its kinda low on range.. i thought 60,000 would do enough but no matter how big the var is it kinda gives me the same results."


There is a limit to the amount of force you can apply, but this is heavily dependent on the Physics Scale (SetPhysicsScale( scale )). Try reducing this. From memory, I believe I set mine to 0.05 as this seemed to work best for my app. However, doing this affects ALL physics so if like me, you were right at the end of the project before you found this, you may have a lot of tweaking on your hands
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Nov 2014 12:51
the physic scale belongs the virtual resolution u had set.
default screen 100 x 100 means 100m x 100meters i believe.
if u use 1024x768 or something u need set this scale.

here u should add .0 because u want float value.
*60000
=
*60000.0

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
haliop_New
User Banned
Posted: 10th Nov 2014 15:34 Edited at: 10th Nov 2014 15:51
cool thanks for the advice(s)
i have now created a simple collision checking for the bullets like this :
so the idea is if it hit anything it will be destroyed
creating a new bullet


checking for changes in velocities


is there a faster way to do so ?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Nov 2014 16:05
maybe try this


or this GetSpriteCollision

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
haliop_New
User Banned
Posted: 10th Nov 2014 16:16
GetSpriteCollision will slow down my app cause you need to check in a loop all physcics sprites
i will try now what you suggested and check with a timer to see which one is faster
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 10th Nov 2014 16:24
GetSpriteCollision is pretty quick, I have hundreds of collision checks in my platform game... Do you really need 1000 bullets? Is it even possible that 1000 bullets will be active at any one time?
haliop_New
User Banned
Posted: 10th Nov 2014 16:32
for some reason the code you gave me crushes the app, it works but suddenly crush..

edit: ok found it , need an Exit command when hit.

ok , so my solution time is : 0.000250 approx

your solution time is : 0.000200 approx

so yeah i guess becouse of the first Exit command in your code it works faster also i get the exact x and y in your solution.

man i think i cannot say anything to express the thank you i owe you.
so , Thank you
haliop_New
User Banned
Posted: 10th Nov 2014 16:34
from my expriance GetSpriteCollision slow down my app..
cause you have to check all of the physics sprites

and yeah i dont need 1000 bullets this is just for stretching the cpu a bit
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Nov 2014 17:22
ok,
i can agree check all with all is slower.
the physics collision list already there.

the agk solution with GetSpriteFirstContact & GetSpriteNextContact
is unesthetic for developing, but maybe the reason was box2d.

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
haliop_New
User Banned
Posted: 10th Nov 2014 18:58
the agk solution with GetSpriteFirstContact & GetSpriteNextContact
is unesthetic for developing, but maybe the reason was box2d.

is it a good thing or a bad i dont understand.
should i use it or not ?
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 10th Nov 2014 19:03
At a quick glance it looks to me as though you are creating sprites but not deleting them every thousand sprites. So a machine gun could soon eat all the RAM. But then, I'm no expert on T1.

-- Jim - When is there going to be a release?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Nov 2014 19:50
i mean,
for writing it looks better this sytax but we not have in agk.


AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
haliop_New
User Banned
Posted: 10th Nov 2014 20:43
jim i delete them i just didnot post the delete function ..
markus ahh i see what you mean.

Login to post a reply

Server time is: 2024-11-25 11:45:20
Your offset time is: 2024-11-25 11:45:20