Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to get Updated position of X and Y when position is changing with time — Gideros Forum

How to get Updated position of X and Y when position is changing with time

simransimran Member
edited May 2014 in General questions
I have 2 classes, In one class, I have code for position of object1 changing with time and in class2, I have code for object2 changing with time, the positions are changing continuously at different rates. Now, I want to figure out if the two objects collide, but how do I get their positions that are changing at difference of less tahn a second, is their any shortcut or efficient method to do that?

Here is how object1 and object 2 are changing their positions:

object 1:
self:setRotation( self:getRotation() + math.random(5,7) )

object2:
x = 215 + math.cos(angle)*195
y = 130 + math.sin(angle)*115

Both of these are part of 2 different classes
Capture.PNG
319 x 492 - 172K

Comments

  • @simran, I was wondering why the image of a clock, then seeing it referenced back in another question, it made some sense.

    1. Object 1 is being rotated around the anchor points randomly, the x and y of those are never going to change (if the anchor point is the middle and the image a square).

    2. The Object2 is being rotated around a circular/elliptical object based on the angle.

    So what are you trying to check for collision? Object1 and Object2? Try to answer the following to allow people to help you.

    a. What is Object 1 - The Clock hands? Are they rectangular/square
    b. What is Object 2 - The Ball?

    and a bit about what are you trying to achieve, if the ball shall move outside of the clock and the hands rotate inside, they will never collide. So passing the 215,130 which are the mid points of the circular orbit of Object2 means nothing since the x,y of Object 1 are unknown.

    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • simransimran Member
    edited May 2014
    @OZApps: Okay, Thank you for asking these :)
    My clock's hands are in weird position, actually I centered them and are rendered at centre when I test it in my phone but in Desktop player, I am getting this position for some reason I really don't know though I used Logical dimensions after scaling, but that's not what I am really worries about right now.

    hey hey, My object 2 is not ball, but the player that in the picture is on rightmost side(please open the picture), not clearly visible otherwise :)

    --> let's say I group all my 3 clock hands, these are rotated around an anchor point so x and y remain the same, but they have some width extending,

    --> My player is moving in an ellipsis and it's position is changing with time(only when the player jumps, it's not on floor)

    Requirement--> what I really want is whenever the player touches any of the clock hands, youLoose method(not given in the code) shall be called, now to achieve this, here is what I did:
    and the collision can be anywhere across the length of any of the clock hands,(so basically this part is what I am not getting)
    I checked collision as soon as x and y of player changed,here is the code:

    x = 215 + math.cos(angle)*195
    y = 130 + math.sin(angle)*115
    for i = 1, groupA:getNumChildren() do
    local sprite2 = groupA:getChildAt(i)
    local oBoxToObox = tntCollision.oBoxToObox
    if i == 1 then
    a = 97
    b = 11
    elseif i == 2 then
    a = 206
    b = 64
    else
    a = 120
    b = 10
    end
    local pointToObox = tntCollision.pointToObox
    tntCollision.setCollisionAnchorPoint(0, 0)
    if oBoxToObox(x,y, 36, 40, cute.anim[self.frame]: getRotation(),sprite2:getX(), sprite2:getY(), a ,b, sprite2:getRotation()) then

    youLoose()
    end

    end


    end

    Now, oBoxToObox should be able to detect collision, everything is in the picture and even then it is not detecting any collision, so this is where I am stuck
  • simransimran Member
    Please help me fix this, kind of urgent and have been trying since then but nothing helped
  • OZAppsOZApps Guru
    Accepted Answer
    Simran, a couple of things that you are missing or overlooking. Here's a quick diagram (yes this is circular not elliptical but the concept would remain the same)

    1. The inner Purple circle is the radius of the Dark Purple hand. The hand would move and cover an area as large as the purple circle. The same goes for the Orange and the Blue circles.

    2. The Salmon colour outer circle is the game play area in which the Ghost (the player character) can move.

    3. For explanation sakes, lets say the short hand radius is 10, the long hand 15 and the longest hand (seconds) is 20.

    To find if a collision occurred or not, check the distance from the centre to the player, if this is more than 10 then it could not have collided with the short hand, if it is more then 15 then it cannot have collided with the long hand and if it is more than 20 then it could not have collided with any of the hands.

    If it is say between 10 and 15, it would have collided with the long hand as it is beyonf the short hand and less than the longest hand. So here to be sure that it did collide with the long hand, you need to check the angle of the long hand and the character, if they are within a range of +/- 5 (depending on your gameplay rules) it could have collided.

    There are many ways to check for collisions, Here we are simply testing if two circles have collided or not. Where the player is a circle and one of the other hands orbit is another.

    Hope this shall get you thinking and closer to getting a solution than you were.
    Movement.png
    384 x 363 - 30K
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
Sign In or Register to comment.