Mathematical problem

OrvilFoxOrvilFox Member Posts: 67
edited March 2016 in Working with GS (Mac)

How to determine the position(x,y) of the green dot by the circle?
Could use all the functions provided by GS.
I need a dynamic equation for this, it will looks like (x=3.5pier-6,y=1.7*r^2) <JUST FOR EXAMPLE! NOT A REAL EQUATION!
I've been thinking about a lot of possible equations but none of them actually work.

Comments

  • ArmellineArmelline Member, PRO Posts: 5,368

    There must be more to your question. The X/Y position of the dot is known to the dot, and can be passed easily to the circle or any other actor. Please explain in more detail what you mean :D

  • OrvilFoxOrvilFox Member Posts: 67
    edited March 2016

    @Armelline said:
    There must be more to your question. The X/Y position of the dot is known to the dot, and can be passed easily to the circle or any other actor. Please explain in more detail what you mean :D

    The green dot is an actor and the circle is another actor.
    Let's see if I want to attach the green dot on that position on the circle.
    Now, the circle starts to rotate, which means that the green dot needs to move with the circle because they are attached. Therefore I think I need an equation showing the relationship between the rotation of the circle and where should the dot move. Then I could use "Constraint Attribute" to achieve my goal. ;)
    :* Maybe it is a little bit hard to understand, so I wish I explained it well. :D

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2016

    @Armelline I think they are wanting to know how to find the x,y position of a point on a circle given the x,y coordinates of the center of the circle. Of course, you'd need to know the measurement of the angle to that point as well.

    Starting point: http://www.mathopenref.com/coordbasiccircle.html

    Edit: didn't see the above post before I answered... glad I was on the right track ;)

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

  • ArmellineArmelline Member, PRO Posts: 5,368

    Do a search for @Socks' fast constrain demo. That can do what you seem to be asking. Unless what you're asking is closer to what @tatiang suggests.

  • OrvilFoxOrvilFox Member Posts: 67

    @tatiang said:
    @Armelline I think they are wanting to know how to find the x,y position of a point on a circle given the x,y coordinates of the center of the circle. Of course, you'd need to know the measurement of the angle to that point as well.

    Starting point: http://www.mathopenref.com/coordbasiccircle.html

    Amazing! This is exactly what I expected, I'll give it a try and see if it works or not.

  • SocksSocks London, UK.Member Posts: 12,822

    @neo1998x said:
    The green dot is an actor and the circle is another actor.
    Let's see if I want to attach the green dot on that position on the circle.
    Now, the circle starts to rotate, which means that the green dot needs to move with the circle because they are attached. Therefore I think I need an equation showing the relationship between the rotation of the circle and where should the dot move. Then I could use "Constraint Attribute" to achieve my goal. ;)

    The green dot's location is:

    X = radius of the circle * cos (circle's angle)
    Y = radius of the circle * sin (circle's angle)

  • OrvilFoxOrvilFox Member Posts: 67

    @Armelline said:
    Do a search for @Socks' fast constrain demo. That can do what you seem to be asking. Unless what you're asking is closer to what @tatiang suggests.

    o:) I can't believe it! You definitely made my day.
    Thanks for providing the resources, now it's working like a champ!

  • OrvilFoxOrvilFox Member Posts: 67
    edited March 2016

    @Socks said:

    @neo1998x said:
    The green dot is an actor and the circle is another actor.
    Let's see if I want to attach the green dot on that position on the circle.
    Now, the circle starts to rotate, which means that the green dot needs to move with the circle because they are attached. Therefore I think I need an equation showing the relationship between the rotation of the circle and where should the dot move. Then I could use "Constraint Attribute" to achieve my goal. ;)

    The green dot's location is:

    X = radius of the circle * cos (circle's angle)
    Y = radius of the circle * sin (circle's angle)

    Thanks, it worked! You are the man!

  • SocksSocks London, UK.Member Posts: 12,822

    @neo1998x said:

    @Socks said:

    @neo1998x said:
    The green dot is an actor and the circle is another actor.
    Let's see if I want to attach the green dot on that position on the circle.
    Now, the circle starts to rotate, which means that the green dot needs to move with the circle because they are attached. Therefore I think I need an equation showing the relationship between the rotation of the circle and where should the dot move. Then I could use "Constraint Attribute" to achieve my goal. ;)

    The green dot's location is:

    X = radius of the circle * cos (circle's angle)
    Y = radius of the circle * sin (circle's angle)

    Thanks, it worked! You are the man!

    P.S what I posted only shows where the green dot is in relation to the circle, it assumes the centre of the circle is x0, y0, but if your circle is elsewhere in your scene (for example in the middle of the scene) then you'd need to add in the circle's location to the equation like this:

    The green dot's X = radius of the circle * cos (circle's angle) + circle's X position
    The green dot's Y = radius of the circle * sin (circle's angle) + circle's Y position

  • OrvilFoxOrvilFox Member Posts: 67

    @Socks said:

    @neo1998x said:

    @Socks said:

    @neo1998x said:
    The green dot is an actor and the circle is another actor.
    Let's see if I want to attach the green dot on that position on the circle.
    Now, the circle starts to rotate, which means that the green dot needs to move with the circle because they are attached. Therefore I think I need an equation showing the relationship between the rotation of the circle and where should the dot move. Then I could use "Constraint Attribute" to achieve my goal. ;)

    The green dot's location is:

    X = radius of the circle * cos (circle's angle)
    Y = radius of the circle * sin (circle's angle)

    Thanks, it worked! You are the man!

    P.S what I posted only shows where the green dot is in relation to the circle, it assumes the centre of the circle is x0, y0, but if your circle is elsewhere in your scene (for example in the middle of the scene) then you'd need to add in the circle's location to the equation like this:

    The green dot's X = radius of the circle * cos (circle's angle) + circle's X position
    The green dot's Y = radius of the circle * sin (circle's angle) + circle's Y position

    Thanks for providing the solution! :#
    One question about your Fast Constrain v2, why does the child disappeared if I move it to the lower layer than the parent?

  • pHghostpHghost London, UKMember Posts: 2,342

    It probably has to do with the sequence in which things are processed by GS.

    The later order of thing is very important!

  • SocksSocks London, UK.Member Posts: 12,822

    @neo1998x said:
    One question about your Fast Constrain v2, why does the child disappeared if I move it to the lower layer than the parent?

    GameSalad scans a project's code like this:

    Lowest layer first > Lowest actor within that layer > Topmost code first within that actor.

    The child actor needs information about the parent's position and rotation to calculate its own position and rotation - that information needs to be generated before the child actor calculates its position, if the child actor is below the parent actor then that cannot happen.

  • zweg25zweg25 Member Posts: 738

    A simple timer should fix this issue?

  • OrvilFoxOrvilFox Member Posts: 67
    edited March 2016

    @Socks said:

    @neo1998x said:
    One question about your Fast Constrain v2, why does the child disappeared if I move it to the lower layer than the parent?

    GameSalad scans a project's code like this:

    Lowest layer first > Lowest actor within that layer > Topmost code first within that actor.

    The child actor needs information about the parent's position and rotation to calculate its own position and rotation - that information needs to be generated before the child actor calculates its position, if the child actor is below the parent actor then that cannot happen.

    Thanks for the information. And I tried to spawn a child actor at a certain position, but it did not, it seem like the actor constrained to the parent even before it spawned. Is this a GS thing too?

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2016

    @neo1998x said:

    @Socks said:

    @neo1998x said:
    One question about your Fast Constrain v2, why does the child disappeared if I move it to the lower layer than the parent?

    GameSalad scans a project's code like this:

    Lowest layer first > Lowest actor within that layer > Topmost code first within that actor.

    The child actor needs information about the parent's position and rotation to calculate its own position and rotation - that information needs to be generated before the child actor calculates its position, if the child actor is below the parent actor then that cannot happen.

    Thanks for the information. And I tried to spawn a child actor at a certain position, but it did not, it seem like the actor constrained to the parent even before it spawned. Is this a GS thing too?

    Sorry I don't know what that means, too vague for me :#

  • OrvilFoxOrvilFox Member Posts: 67

    @Socks said:

    @neo1998x said:

    @Socks said:

    @neo1998x said:
    One question about your Fast Constrain v2, why does the child disappeared if I move it to the lower layer than the parent?

    GameSalad scans a project's code like this:

    Lowest layer first > Lowest actor within that layer > Topmost code first within that actor.

    The child actor needs information about the parent's position and rotation to calculate its own position and rotation - that information needs to be generated before the child actor calculates its position, if the child actor is below the parent actor then that cannot happen.

    Thanks for the information. And I tried to spawn a child actor at a certain position, but it did not, it seem like the actor constrained to the parent even before it spawned. Is this a GS thing too?

    Sorry I don't know what that means, too vague for me :#

    Umm, just use the "Spawn actor" to spawn a child actor, let's say at x=50 y=30.
    If the parent actor didn't move, it will spawn at x=50 y=30.
    But if the parent actor moved, it will spawn at somewhere else maybe x=81, y=29.
    How do I spawn the child actor at x=50 y=30 despite the movement of the parent actor?

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2016

    @neo1998x said:
    Umm, just use the "Spawn actor" to spawn a child actor, let's say at x=50 y=30.
    If the parent actor didn't move, it will spawn at x=50 y=30.
    But if the parent actor moved, it will spawn at somewhere else maybe x=81, y=29.
    How do I spawn the child actor at x=50 y=30 despite the movement of the parent actor?

    Whether the parent actor (the actor that is doing the spawning) moves or does not move will have no effect on the location of the child actor, if you set the parent actor to spawn the child at x50, y30 then that's where the child will be spawned regardless of the parent's motion.

  • OrvilFoxOrvilFox Member Posts: 67
    edited March 2016

    @Socks said:

    @neo1998x said:
    Umm, just use the "Spawn actor" to spawn a child actor, let's say at x=50 y=30.
    If the parent actor didn't move, it will spawn at x=50 y=30.
    But if the parent actor moved, it will spawn at somewhere else maybe x=81, y=29.
    How do I spawn the child actor at x=50 y=30 despite the movement of the parent actor?

    Whether the parent actor (the actor that is doing the spawning) moves or does not move will have no effect on the location of the child actor, if you set the parent actor to spawn the child at x50, y30 then that's where the child will be spawned regardless of the parent's motion.

    Simply add the rule:

    The parent didn't move, so the child spawned at the right position:

    The parent moved, the child spawned at somewhere else:

  • OrvilFoxOrvilFox Member Posts: 67

    :s Still need help!
    I can't spawn child actors at a position.

  • SocksSocks London, UK.Member Posts: 12,822

    Hmmmm . . . . let me have a think, the project wasn't really designed to do precisely what you want, and your mission-creep makes it hard to predict what is next on your list of things this project must do :D . . . but I expect all you need do is allow for an offset of some kind, I've not got access to the project or GS at the minute, but I'll try and work it out on paper . . . back in a minute . . .

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2016

    Ok, for it to work how you want the rules for the child actor should look like this:

    Change OFFSET to parent's rotation.
    Change LocalX to selfX
    Change LocalY to selfY
    Change LocalRotation to selfRotation
    Change Radius to magnitude( parentX - selfX , parentY - selfY )
    Change Angle to vectorToAngle( selfX - parentX, selfY -parentY )

    Constrain selfX to Radius *cos( Angle + parent's rotation - OFFSET )+ parentX
    Constrain selfY to Radius *sin( Angle + parent's rotation - OFFSET )+ parentY
    Constrain selfRotation to LocalRotation + parent's rotation - OFFSET

    That should work, I can't remember what I called the attributes in the actual project, but you should be able to work out which is which . . . . basically all I am adding in is an offset for the child's rotation.

  • OrvilFoxOrvilFox Member Posts: 67

    @Socks said:
    Ok, for it to work how you want the rules for the child actor should look like this:

    Change OFFSET to parent's rotation.
    Change LocalX to selfX
    Change LocalY to selfY
    Change LocalRotation to selfRotation
    Change Radius to magnitude( parentX - selfX , parentY - selfY )
    Change Angle to vectorToAngle( selfX - parentX, selfY -parentY )

    Constrain selfX to Radius *cos( Angle + parent's rotation - OFFSET )+ parentX
    Constrain selfY to Radius *sin( Angle + parent's rotation - OFFSET )+ parentY
    Constrain selfRotation to LocalRotation + parent's rotation - OFFSET

    That should work, I can't remember what I called the attributes in the actual project, but you should be able to work out which is which . . . . basically all I am adding in is an offset for the child's rotation.

    Awesome! Although I didn't fully figure out how it processed yet but it works perfectly!
    Thanks :D I think that's all I need for this project.
    I'll definitely credit you since those equations you provided is the core of this game ;)
    What game will this be? Let's wait and see :)

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2016

    @neo1998x said:
    Awesome! Although I didn't fully figure out how it processed yet but it works perfectly!

    Good ! Didn't get to test it myself, glad it works for you.

    @neo1998x said:
    I'll definitely credit you since those equations you provided is the core of this game ;)

    No need to credit me. Please don't credit me.

    @neo1998x said:
    What game will this be? Let's wait and see :)

    Circular Flappy Bird ? :p :)

Sign In or Register to comment.