Pls help.. how to detect the player position if near to enemyplayer position?
rainhasntstop
Member Posts: 43
Question: How to detect the player position if near to enemyplayer position?
in x and y position..
i want my enemy to shoot when player position is near to enemyplayer position?
Comments
You can use the magnitude() function for this. Do a Google search for magnitude gamesalad for more information but here's the basic idea:
When numeric expression magnitude(game.playerX-self.Position.X, game.playerY-self.Position.Y) ≤ 50
[shoot]
You'll need to constrain game.playerX to self.Position.X in the player actor and the same for the Y position. In the rule above, 50 represents 50 pixels between the two actors' positions.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang, beat me to it! But below is a demo I worked up for you to show the concept.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
ohh thank you so much.. that works well
Followup Question: how can i spawn the bullet from enemyplayer in the
(direction where my player is)?
Q: the direction of the bullet where my character is standing
@jamie_c jamie cross from youtube?
wow your one of my idol.. I've watched alot of videos you've created on youtube.. and it helps me alot..
@tatiang thanks for helping
You're welcome! And @jamie_c's tutorials are great. I often recommend them to new and experienced users alike.
When you spawn the bullet, you can use a Move To behavior and put game.playerX in the X position field and game.playerY in the Y position field. Set it relative to Scene.
I rarely use Move To so I can't remember if it will just move to the initial position (e.g. if the player moves after the bullet is spawned the bullet won't follow the new position of the player). If it does follow the new position and you don't want it to, you would just have two Change Attribute behaviors in the bullet actor to change self.targetX to game.playerX and self.targetY to game.playerY and then use those self attributes in the Move To behavior instead. Hope that makes sense!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@rainhasntstop, @tatiang, thanks guys, I appreciate the kind words.
Glad the demo helped out some.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Sir @tatiang i dont want it to be homing! it keeps following my player
if i use (move to game.playerX and game.playerY of my player)
and the image is not proportionate to bullet
I've tried to Spawn Actor a bullet to my EnemyPlayer to the Direction of
-vectorToAngle( self.Position.X - game.playerX , self.Position.Y - game.playerY )
On my bullet actor
i put Change Velocity
it works well when my player is in upper or lower of the enemyplayer but when my player is in right side of the enemyplayer the bullet spawned in left, and when my player is on left side of the enemyplayer, the bullet spawned in right side?
pls help Sir @tatiang and Sir @jamie_c
Right, that's why I suggested that you "copy" the game attributes' values into self attributes in the bullet and use those self attributes in the Move To behavior. Were you able to try that?
I'm not sure what you mean by "the image is not proportionate to bullet."
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Sir @tatiang pls take a look at
Done my problem is solved..
but the bullet image is not facing at my player when its moving
i cant put my zip file? when im dragging my file here..
i want to show you what my problem is..
another question: how can i put my zip file here? im using mac
when i drag my zip file here nothing happens and just download a new file that i drag here
You'll need to upload your .zip file to a file-sharing site and then post the download link here.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang thank you so much for the help.. i found out what i need
im so happy that i learned alot
@tatiang how can i mark this thread as flag to answered