How do I retireve physics properties after drag and drop

Get help using Construct 2

Post » Sat Jan 17, 2015 7:12 pm

I have a power up that when the player touch the screen, the time is frozen and then he can drag and drop the object. This object has physics behavior, which lose all it's properties like velocity, direction, etc when dragged.

I thought about getting all of this and store it in a variable. However, we have expressions to retrieve angular velocity, center of mass, mass, and velocityX and Y, but not the overall velocity.

Summing up, after dragged and set scale time to 1 again, the object doesn't keep the velocity and direction, it drops straight down.
Posts: 604
Reputation: 6,691

Post » Sat Jan 17, 2015 10:35 pm

So, yes, you're going to need to store the variables. I've not worked with physics objects since Construct classic though. I assume that only the velocity is lost on this time freeze.

Have two instance variables in the object labelled velocityx and velocityy or any other names which mean the same. When the time is frozen, set the variables to the objects x velocity and y velocity. When time is resumed, use the object.setvelocity using the parameters of the stored velocity x and y.

This works because a velocity can be split into its components, in however many dimensions you are working with. In this case we are on a plane so we need to consider only x and y. Using trigonometry we can look at an objecs velocity in terms of a line, where the length of the line is the velocity and the direction the line is pointing is the direction of velocity. Since the line is straight and in the plane then we can calculate the velocity in both x and y velocity. This is also true in reverse with the overall velocity equalling sqrt(vx^2 + vy^2) which is synonymous with pythagoras' theorem.
Nothing goes unanswered!
Posts: 434
Reputation: 3,446

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests