how to make an enemy is close warning actor moving in a circle on the position where the enemy is?

-Timo--Timo- Member Posts: 2,313
hey guys.

how to make an actor that constrains the position of the enemy in a circle.
I have 1 enemy and he is not inside the camera. I want an actor to be inside the camera on shows where the enemy is.
so when the enemy is above the player the actor is also above the player. and when the enemy is left from the player the actor is also left from the player. but now I want the warn actor to move in a circle around the player. (the enemy is not moving in a circle)
hope I explained enough :) can a circle expert help me? :)
thanks,

-Timo-

Best Answers

  • SocksSocks London, UK.Posts: 12,822
    Accepted Answer
    @timolapre1998

    Ah! Makes sense now ! :)>-

    I'm not at my computer so this might be a little wrong (I'll check it later when I get home . . ) but the basic equation should be . . .

    For the warning actor:

    Constrain position X to: [the distance you want the warning actor to orbit the player] *cos ( vectorToAngle ( enemy position X - warning actor position X, enemy position Y - warning actor position Y ))+ player position X

    Constrain position Y to: [the distance you want the warning actor to orbit the player] *sin ( vectorToAngle ( enemy position X - warning actor position X, enemy position Y - warning actor position Y ))+ player position Y
  • SocksSocks London, UK.Posts: 12,822
    edited November 2013 Accepted Answer
    @timolapre1998

    Just checked . . . this works . . . .

    With the warning pointer placed in the scene - and unlocked - place these three constrains directly into the actor in the scene:

    Constrain self.Position.X to:
    100*cos( vectorToAngle( scene.Background.The Player.Position.X - scene.Background.The Enemy.Position.X , scene.Background.The Player.Position.Y - scene.Background.The Enemy.Position.Y )+180)+ scene.Background.The Player.Position.X

    Constrain self.Position.Y to:
    100*sin( vectorToAngle( scene.Background.The Player.Position.X - scene.Background.The Enemy.Position.X , scene.Background.The Player.Position.Y - scene.Background.The Enemy.Position.Y )+180)+ scene.Background.The Player.Position.Y

    Constrain self.Rotation to:
    vectorToAngle( scene.Background.The Player.Position.X - scene.Background.The Enemy.Position.X , scene.Background.The Player.Position.Y - scene.Background.The Enemy.Position.Y )+180
  • SocksSocks London, UK.Posts: 12,822
    Accepted Answer
    @timolapre1998

    Here's a quick demo (file attached)

    You can drag the enemy (green) and the player (white) around to see the enemy warning pointer work its magic.
  • SocksSocks London, UK.Posts: 12,822
    Accepted Answer
    @timolapre1998

    Here's a version with a manoeuvring enemy (file attached):

  • SocksSocks London, UK.Posts: 12,822
    edited November 2013 Accepted Answer
    @timolapre1998
    . . . how to change to color alpha on how far the enemy is away from player? so when enemy is close the warning is alpha 1 and when far its 0 :)
    Constrain self.colour.red to 1-magnitude( scene.Background.The Player.Position.X - scene.Background.The Enemy.Position.X , scene.Background.The Player.Position.Y - scene.Background.The Enemy.Position.Y )/800

    Adjust the '800' to taste and device size.

    EDIT - I've assumed a red warning pointer . . . but you can of course apply this formula to any (or all) of the colour channels, or even just the alpha channel.


    Hold on, let me make a demo (which you promise not to mark as 'answer' !! 8-X)
  • SocksSocks London, UK.Posts: 12,822
    edited November 2013 Accepted Answer
    Here you go . . . . (file attached)

Answers

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I'm sure there's a circle expert round here somewhere
  • SocksSocks London, UK.Member Posts: 12,822
    hey guys.

    how to make an actor that constrains the position of the enemy in a circle.
    I have 1 enemy and he is not inside the camera.
    I want an actor to be inside the camera on shows where the enemy is.
    so when the enemy is above the player the actor is also above the player. and when the enemy is left from the player the actor is also left from the player. but now I want the warn actor to move in a circle around the player. (the enemy is not moving in a circle)
    hope I explained enough :) can a circle expert help me? :)
    thanks,

    -Timo-

    That's a very confusing post ! :)) 8-X :-O

    Circles in GameSalad are very easy, if you can make the question a little clearer I'm sure it should be straightforward enough.
  • -Timo--Timo- Member Posts: 2,313
    @socks
    hmm.. I am very bad in explaining ;)
    I have a player and a enemy. the player has the control camera behavior and the enemy is almost always off screen. when the enemy is off screen you still need to know where the enemy is. so when the enemy is off screen there is a other actor that points to the enemy from the player. so when the enemy is off screen the warning actor is on screen and points to the enemy. when the enemy is left from the player the warning actor is left from the actor on screen. the warning actor moves in a circle pointing to the enemy :)
    hope I explained enough :D
  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2013
    Wow, you really like working with cos and sin, right? Looks really amazing for making the formula on the go :D
    @sadida172

    Actually it was a little bit wrong, I needed to extract the angletovector thing from the player and the enemy rather than the warning pointer and the enemy - but the basic idea was there.

    Sin and Cos are incredibly useful, you don't even need to use both, just using either you can make circles and spirals and push actors through all the colours of the rainbow/spectrum and make things bounce and swing and make joints and are great for making random unpredictable evolving paths and a million other things, really useful, really worth learning and bizarrely simple once you work out what sin (or cos) are actually doing. :)>-
  • -Timo--Timo- Member Posts: 2,313
    edited November 2013
    @socks Wow really amazing :) very helpfully, THANKS! :D
    do you also now how to change to color alpha on how far the enemy is away from player? so when enemy is close the warning is alpha 1 and when far its 0 :)
  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2013
    @CodeWizard
    @Codemonkey
    @dgackey

    There is an issue with the forum whereby a post accepted/marked as the 'answer' has its attachments deleted. Someone asks a question, it's often replied to in the form of a demo project, if the person asking the question accepts this response as the answer, the forum then dutifully deletes the attachment !

    Of course the person asking the question got their answer, but the thread then becomes largely useless to those in the future looking for answers to similar questions and the person taking the time to make the demo has their efforts erased and we end up with lots of . . . "Cheers for the demo, that solved the problem" and "Thanks, that's a much faster way of doing it" . . . but no actual file for people to look at, just a few orphaned clues . . . which kinda' defeats the point of attachments.

    This has been going on for months now, there are workarounds (only posting the typed out code, using external file hosting sites) but the problem is that people always aren't aware of the issue, so just use the built in attachment link not knowing their efforts are often doomed 8-X, I know you've got a lot of your plate, but it'd be cool if there was an easy fix for this at some stage.
  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2013
    Here are those deleted demo files again: (both in one zip file)

    @timolapre1998 Don't mark this as ANSWER !!! if you do the files will be lost forever !! 8-X
  • -Timo--Timo- Member Posts: 2,313
  • -Timo--Timo- Member Posts: 2,313
  • SocksSocks London, UK.Member Posts: 12,822
    thats 5 answers :) well earned :D really really thanks :)
    I'm going to sell them on ebay.

    5 'answered' awards, hardly used, one careful owner - £200
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @Socks

    @Socks said:

    There is an issue with the forum whereby a post accepted/marked as the 'answer' has its attachments deleted. Someone asks a question, it's often replied to in the form of a demo project, if the person asking the question accepts this response as the answer, the forum then dutifully deletes the attachment !

    Of course the person asking the question got their answer, but the thread then becomes largely useless to those in the future looking for answers to similar questions and the person taking the time to make the demo has their efforts erased and we end up with lots of . . . "Cheers for the demo, that solved the problem" and "Thanks, that's a much faster way of doing it" . . . but no actual file for people to look at, just a few orphaned clues . . . which kinda' defeats the point of attachments.

    This has been going on for months now, there are workarounds (only posting the typed out code, using external file hosting sites) but the problem is that people always aren't aware of the issue, so just use the built in attachment link not knowing their efforts are often doomed 8-X, I know you've got a lot of your plate, but it'd be cool if there was an easy fix for this at some stage.

    The new editor bar's attachment button is supposed to resolve this issue.

    image

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.