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 / shooting bullet from the player sprite angle

Author
Message
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 22nd Jul 2016 09:40
I have used this code to control the player, as taken from an example posted on here:



I am using physics with gravity of 0,0 so I can have a gauntlet game type movement, but what I want to know is how do you fire a bullet at the angle the player is at?, I an get the angle of the player using more code from here
this is my function for shooting a bullet,or trying to!

neither force or impulse seen to do what I need
Hail to the king, baby!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 22nd Jul 2016 09:58
i guess your bullet force is in world coords, you should use vx and vy.
something like
factor=20000.0
forcex=Cos(PlayerAngle)*factor
forcey=Sin(PlayerAngle)*factor
SetSpritePhysicsforce(idbullet,getspritexByOffset (idbullet),getspriteyByOffset (idbullet),forcex,forcey)

i think setspritephysicsimpulse is better because its applied only once

see also SetPhysicsScale ( scale )

get the offset for bullet you can use this
GetWorldXFromSprite ( iSpriteIndex, x, y )
GetWorldYFromSprite ( iSpriteIndex, x, y )
AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 22nd Jul 2016 10:33 Edited at: 22nd Jul 2016 10:34
I am not too good with maths, I tried your suggestion and it didnt work, however, I fiddled about with the code,not having an idea really, and this change seemed to work!:



though I messed around and are probably doing something daft, it seems to do what I wanted anyhow!
Hail to the king, baby!
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 22nd Jul 2016 11:29 Edited at: 22nd Jul 2016 11:35
the problem I have now is that there is slight interaction between the player and the bullet when it is fired,coz both physics are enabled of course,so it can throw the bullet off its initial angle
**edit** never mind,I used SetSpritePhysicsIsSensor(playersprite,1) upon creating the player so this solves it,I never knew I could still issue physics velocity on them!
Hail to the king, baby!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 22nd Jul 2016 12:53
maybe you can use SetSpriteGroup, see Description
AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 23rd Jul 2016 07:53
Take Markus's advice, learn to use the SetSpriteGroup commands. These come in very handy when creating action games! That way you can control what can effect what in-game..the player and it's bullets won't effect each other and you can make it appear bullets appear either inside the sprite or underneath it. Same can be done with enemy sprites that fire at the player.
My workstation was destroyed in a fire, help me out and get free media for AppGameKit and Game Guru: https://www.gofundme.com/bfpm0g

Login to post a reply

Server time is: 2024-11-25 03:45:44
Your offset time is: 2024-11-25 03:45:44