How to get a positive "speed" variable w/ physics?

Get help using Construct 2

Post » Thu Feb 28, 2013 5:25 am

Hi guys. What I'm trying to do is basically calculate damage with velocity and mass (IE, throwing a ball at someone does damage based on speed and weight)
However, I quickly realized that the physics X and Y velocities can be either positive or negative while moving at fast speeds depending on direction.
Here's what I'm using:
Enemies.Health - ((MovableObjects.Physics.Mass * MovableObjects.Physics.VelocityX +MovableObjects.Physics.VelocityY) * 0.05)

Basically, I just want a way to have one "speed" variable that isn't dependent on X and Y.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Thu Feb 28, 2013 5:31 am

abs(MovableObjects.Physics.VelocityX) will turn a negative into a positive

Are you intending to calculate (mass*velocityX)+velocityY? or mass*(velocityX+velocityY), in which case you would need more brackets.
B
7
Posts: 38
Reputation: 476

Post » Thu Feb 28, 2013 5:36 am

Oh. It's supposed to be mass*(velocityx+velocityy).
What is "abs" exactly?
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Thu Feb 28, 2013 5:48 am

@Sunshin abs returns an absolute value, basically a polsitive number. SO if the number is -1 abs will return 1. If it is -125 abs will return 125.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Thu Feb 28, 2013 6:03 am

I see. Thank you guys for your help.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests