Actor respond to player only if its within designated radius.
GSlostsoul
Member Posts: 22
Hi,
I'm using the swing knight template & have no idea how to make the line constrain to a certain length. In the current template, the line can be connected no matter where the player is. What I'm trying to make is, If player is not within a certain radius of the post, the line then will not connect with player. Pls help anybody. Pls bear with my poor language. Thank U.
Comments
Look up 'magnitude'.
Hi Socks, thank U for advice. Are U referring to the dog on leash discussion?
Hi Socks, which part & how to tweak the swing knight template?
Really confused with all the formulas.
Can U guide me how to do it?
Thank U
!?!??
My post only has three words 'Look up 'magnitude' - none of which are 'dog', 'on', 'leash' or 'discussion' !
Like I say, look up 'magnitude', it is a function that allows you to detect the distance between two objects, so you can use it to see whether the player and post are close enough to allow the line to connect.
I will make you a quick demo . . . . .
Demo
Link: https://www.mediafire.com/?deci63d423a7hq2
(move the squares around !)
. . . . . .
How magnitude works, this is the function:
magnitude (X of actor 1 - X of actor 2 , Y of actor 1 - Y of actor 2 )
This will tell you the distance between actor 1 and actor 2, it doesn't matter where you place this formula, in actor 1, actor 2 or even a completely separate actor, it's just a math formula that will produce a number (the number of pixels between the two actors you've used in the formula).
. . . . . .
I've also wrapped the whole formula in a 'floor' function, this just rounds the number down to a whole number (basically gets rid of the decimal places). The floor funciton works like this:
floor (place whatever you want to be rounded down in here)
So: floor (104.543) will give you 104 . . . and floor (34.832) will give you 34.
You don't need to use 'floor', I just used it to make the number display a little neater.
. . . . . .
So . . . if you know the distance between two actors you can make a rule that says . . . if distance between two actors is less than - for example 100 pixels - then do whatever you want to do (blow it up, draw a line, add 10 points to the score . . . or whatever) . . . and that rule will look something like this:
If magnitude (X of actor 1 - X of actor 2 , Y of actor 1 - Y of actor 2 ) < 100 then change Score to Score + 10 . . .
Hi @GSlostsoul
As @Socks suggests, magnitude is a useful function to use and would work in your situation admirably.
But there's an alternative (there often is in GameSalad!) and that's relatively simple to do:
So to obtain the information that the player is within a certain radius about the post, place an invisible actor over the post, set its collision shape to circle. Now you can use the collision Rule between this radius and your player, so when colliding, the player is close enough.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Hi Socks & gyroscope, thank U for guiding. I think I got it. But now when I place the 2nd post in the scene, both will not work.
I'm trying to make a game where by player need to cross by swinging to the 1st post if it is within radius. This is solved thanks to both of U.
When player is swinging on the 1st post & if it is within radius of the 2nd post, then player can swing to 2nd post.
How can it be done.
Hi gyroscope,I'm trying to make a game where by player need to cross by swinging to the 1st post if it is within radius. This is solved.
Now I'm trying to make player to be able to swing to the 2nd post from the 1st if player is also within 2nd post radius.
But when I drag the 2nd post into the scene, both post will not work.
1st & 2nd post uses the same prototype actor.
Pls advise me how to do it.
Thank U