I'm working on a game engine that will incorporate jumping between ropes.
I was going to put this in the games forum, but I want to use proper maths, rather than trickery to achieve it, so I thought I'd be better off here.

I have the character running around, so I have gravity, inertia, values for speed and direction, swing radius, etc. But I don't know how to calculate the rotational velocity based on the 'incoming' velocity. To be honest, I don't know where to start. Should I constrict the character to a cirular path, or do it manually with trig?

I also need to be able to exit the swing and keep the same velocity and direction upon exit, but I think I know how that's done. It's just calculating the initial speed as he grabs the vine.

I'd provide some data, but there's not much I've got so far that would relate, if you know what I mean.

Here's something I sketched up here at work quickly, to try and explain what I was talking about last night.

What it boils down to is that I need to be able to work out the acceleration/deceleration once the guy is swinging at a certain radius. I want to use maths for this, as it will give a more realistic interpretation of the forces involved.

I'd start with a guy (this doesn't relate totally to the picture) running along X at a set rate, say 1.5m/s. During this run, he would join the rope at it's bottom point, and start swinging. he would obviously lose speed, as he will be swinging up. He would then run out of speed, and start accelerating back down, and will hit the ground at just less than the speed he started at.
This way, the guy would join the rope, and start his rotation at 1.5m/s, which would then decrease, because of the climb.

As is usually the case with me, I can work out most of the theory, it's just the number-busting that breaks me.

Last edited by drunkenmaster2000; 02-26-2003 at 09:32 AM.

i tryin to do the same thing myself (half-pipe snowboard game)and havin real trouble. one thing that might help (which you prolly already got) is converting a distance to an angle along a circular path.

Code:

rotation = (speed / radius) * (180/Math.PI);

that way you have a starting point and an angle where you can calculate the next position of the character. i figure you could apply gravity to the speed prior to doing the calculation, it should only affect speed because the motion is constrained to the circle.

Graphics Attract, Motion Engages, Gameplay Addicts
XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

Originally posted by BlinkOk i tryin to do the same thing myself (half-pipe snowboard game)and havin real trouble. one thing that might help (which you prolly already got) is converting a distance to an angle along a circular path.

Code:

rotation = (speed / radius) * (180/Math.PI);

that way you have a starting point and an angle where you can calculate the next position of the character. i figure you could apply gravity to the speed prior to doing the calculation, it should only affect speed because the motion is constrained to the circle.

Thanks for replying m8.

I've spent some time working it out and have come to the same decision.
As far as gravity is concerned, I think if you multiply gravity by the sin of the angle, and you should get something that resembles gravitational force at the given angle ( 90 degrees = full gravity, 135 degrees = 0.5 * gravity, 180 degrees = 0 * gravity.) I have yet to implement it, but when I do, I'll post the results up here. Along with the game, of course.

if you want you could have a go at my problem;here's my useless attempt; http://www.nlc.net.au/~oceana/swift/misc/math1.swf http://www.nlc.net.au/~oceana/swift/misc/math1.fla
this is the way i'm tryin to do it;
the top-down view shows a top down view of the direction which the player is facing. when you hit the left/right arrow keys the player turns left/right. The red-cross identifies the players speed. i figure out the distance from the center of the mc to the cross and apply that to a circle and get the angle. this gives me the rotation (along the y axis) that i need to apply to the player (i know it's not 100% accurate but for my purposes it'll do).
Now is when it all goes to pot. i cannot for the life of me figure out how to apply gravity!!
thanks
Blink

Graphics Attract, Motion Engages, Gameplay Addicts
XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

We're both approaching the same problem here, but I think, from different angles.

In the engine I'm making (platform game) gravity is a constant, and it's effect will be modified by the angle that the character is 'hanging at'.

Basically it boils down to this:

at the bottom of your circle, gravity will have 0% effect on motion. At the side of the circle, it will have 100% effect on motion.

The simplest way I can think of doing this, is to get the sine of the angle. (this is from memory, not sure it it's true, (also done in degrees))
sin(180) = 0 - at the bottom of the circle
sin(90) = 1
sin(270) = 1
sin(0) = 0

^^ this might be cos, you'll have to check it with a calculator.

Like a pendulum? - Look into simple pendulum physics and conservation of energy. Energy before = energy after.

Example - start at bottom of pendulum (potential enregy 0) and give a knock. Only energy is kinetic (mv^2/2). that'll get converted into potential (mgh) where h is height from bottom of circle (and can then be converted into angle from centre of circle to find position). So if all initial kinetic energy converted into potential, it'll stop at some point, h.

before:
PE + KE = 0 + mv^2/2

after:
PE + KE = mgh + 0

these must be equal (neglecting friction). That's the real way, but maybe you can do a simpler version and fake it so it just looks like that. Just thought you might be interested.

Thanks for that, jonmack, my brain just popped. I'd like to look into it though.

back to my current problem though.

Here is a section of code:

Code:

if (glock) {
// Distance to travel
swingdist = xvel
// swingdist = Math.sqrt((xvel*xvel)+(yvel*yvel)); // correct
// Radius and circumference, need only be calculated once - Distance between belt and grapple
distx = _x - _root.newgrap._x; // correct
disty = _y + grapbelt._y - _root.newgrap._y; // correct
if (!circcalc) {
roperad = Math.sqrt((distx*distx)+(disty*disty)); // correct
swingcirc = 3.14159265 * roperad * 2; // correct - 2 pi r
circcalc = true;
}
// Our current angle in radians and in degrees
currangle = Math.atan2(distx,disty)+Math.PI; // correct (radians)
theangle = (57.29578*currangle); // for display only
// the amount we need to add to the angle, in radians
addangle = ((swingdist/swingcirc)*360)/57.29578; // correct (radians)
swingangle = currangle + addangle; // (radians)
// this will give us the target coordinates
destx = (Math.sin(swingangle)*roperad);
desty = (Math.cos(swingangle)*roperad)+ grapbelt._y;
this._x = destx;
this._y = desty;
} else {
//carry on as per usual
}

okay, when the grapple becomes active, this bit of code will kick in on the 'char' (main character movieclip).

as you can see from it's current state, it's not working very well. But I've been staring at this thing all damn day, and I'm not getting anywhere.

I'd appreciate it if one of you guys could have a glance through and see if I made any glaring errors.

I checked each section with various different tests, and at the time of testing, they all produced the right results. I'm really stumped here.

Okay, I think I understand the basics of the PE/KE stuff, but before I can try implementing it, I need to be able to get the char clip to orbit around it's central point.

I've clipped the code down to basics. I made the angle to add a constant, rather than derived, which should remove any errors there, And I only calculate the current angle once, so that should be a constant.

The trouble is, he's supposed to move anticlockwise at a set radius, and he does, until he gets to about 4'o clock, then he just shoots off to the side, and sort of sticks there.

I'm pretty sure I've just made some bean-error in my code, but I can't find it.

Code:

if (glock) {
mex = this._x; // for display/ease purposes
mey = this._y + grapbelt._y; // for display/ease purposes
// Radius need only be calculated once - Distance between belt and grapple
distx = mex - _root.newgrap._x; // correct
disty = mey - _root.newgrap._y; // correct
if (!circcalc) {
roperad = Math.sqrt((distx*distx)+(disty*disty)); // correct
currangle = Math.atan2(distx,disty)+Math.PI; // correct (radians)
swingangle = currangle; // (radians)
circcalc = true;
}
// the amount we need to add to the angle, in radians
addangle = -0.5/57.29578; // one degree, in radians
swingangle += addangle; // (radians)
xvel1 = (Math.sin(swingangle)*roperad)+distx;
yvel1 = (Math.cos(swingangle)*roperad)+disty;
this._x += xvel1;
this._y -= yvel1;
} else {
//Carry on as per usual
}

please help if you can, this is driving me mental, and my eyes are starting to sting..

Edit: After browsing through some 50 websites, I have found 'exactly' what I'm looking for, but it's an applet, so no way of finding out how it's done.

I was using the wrong offsets, making me look somewhat divvy. I was using the offset from the character's current position, and not from the pivot point.

I'm gonna go soak my head now. And probably punch myself in the face.

Latest version is up, with a properly circling character. (basic circling)

Okay, after a brief soaking, I tidied my code up a little (very little, actually), and am at the point where I can just give it an angle, and it will go to said angle. I also have left and right set to influence the swing speed (like stinking your legs out on a swing, etc.) So now I just have to calculate gravity, and add it in there every frame.

This is where I come unstuck. I have been through several websites explaining the physics needed to do this, and the calculations, but I can't figure out how to get these calculations into flash.

my variables are:

mass
gravity
radius
velocity
original angle (from which I can derive height)

I haven't started writing any code yet, but I'm so confused that I don't think it will help. It is some combination of the above, but god knows what.

I only need to work out what angle I will be moving to given my current angle, velocity, and gravity.

Blinkok, I think I found what wee are both looking for on bit-101's site - www.bit-101.com go to July 8 2002. Sadly, the source for this one is no longer on his site. I asked for a copy on the forums there, but I don't know if anyone will have it.

I hope they do, cos it looks totally beyond me. :|

As far as my game thing goes, it's coming along quite well, I've managed to work out the calculation for exit velocity, but with out the corresponding calculation for entry velocity, it doesn't flow too well. Providing it's just the opposite of exit vel, then I should be able to do it after work tonight.

i think iŽll buy the cd,too,i have all the flas on various different cd s,so its no fun searching for a particular one..
drunkenmaster,switch your pm on or send me a pm please

lol, I only just saw my typo in the thread title Don't think I'm stupid, But maths had probably beaten me in that evenings knife battle, and left me weary.

Nevertheless, I've made some progress, as I said, and as it turns out, I don't think bit-101's fla is really what I'm after, although it is close.

I've managed to work out the rotation speed, the angle and velocity on exit, and recently the code that works out how much speed you lose from hitting the swing circumference at an angle (which I think I fluked )

Tonight, I should be able to add the gravity calculations for a rigid arm system, and from there, decide if I want to do a sprung-arm one too (which would be cool)