Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → How many times has this been attempted?
How many times has this been attempted?
2004-12-09, 4:53 AM #1
This issue has come up before:
jumping straight up from a surface the player is attached to that isn't standard (ClearPhysicsFlags(player, 0x800); and SetPhysicsFlags(player, 0xB0); typically used to allow player alignment to surfaces).

I took a swing at this yesterday and got decent results, but rather than keep straining myself to perfect it, I'd figure I'd offer this one up to the JK physics gods (like Hell Raiser).

So far, using the following in a fast pulse (0.01 works well, 0.1 is decent) works somewhat; it works great when the player is on a wall that's at a 90 degree angle to standard flat ground, but sucks on angled slopes (especially 45 degrees):

Code:
   if(GetThingAttachFlags(player) == 0)
   {
      SetThingVel(player, VectorAdd(
      VectorSet(VectorX(GetThingVel(player)), VectorY(GetThingVel(player)), 0),
      VectorScale(GetThingUVec(player), VectorZ(GetThingVel(player)))
      ));
   }


The main problem is calculating the Z velocity. I tried saving initial values, or differences and readding them in, but all resulting in bleh results.

QM
2004-12-09, 11:44 AM #2
Are you trying to find the right vector for jumping off of a wall/ceiling? If so, I have the right code.

:)
2004-12-09, 11:59 AM #3
Quote:
Are you trying to find the right vector for jumping off of a wall/ceiling?


Yes, yes I am. =D I'd LOVE to see it if you're willing to post. I tried at least a dozen different equations to get it to work, but I could never get the modified VectorZ for SetThingVelocity(player... correct.

QM
2004-12-09, 12:00 PM #4
My version that I have tested:
Code:
		// Detect if player is jumping from this surface.
		velocity_vec = GetThingVel(player);
		if (VectorZ(velocity_vec) > 0)
		{
			// Establish proper direction of player's jump.
			vec = VectorSet(VectorX(velocity_vec), VectorY(velocity_vec), 0);
			velocity_vec = VectorAdd(vec, GetThingUVec(player));
			// Set player's direction to proper direction.
			SetThingVel(player, velocity_vec);
		}


It looks like the only difference is I didn't use the VectorScale because I wanted the player to jump perpendicular to the surface.

I hope that helps,
:)

[Edit: QM, do you use an instant messenger? It can be useful for things like this.]
[Edit2: Took out misleading text about VectorScale.]
2004-12-09, 12:23 PM #5
I have AIM, name QuibMask, but don't use it often.

Your code doesn't do what I want either unfortunately. I was using VectorScale so that gravity would affect you depending on your look vector (whatever is "down" compared to your orientation is the direction you fall). Your code actually caused me to fly since it always sets the player's Z velocity to 0 then sets 1 force in whatever direction is "up" so when standing on a basic level surface, my Z velocity was continually being set to 1.

My most complex attempt was:
Code:
      SetThingVel(player, VectorAdd(
      VectorSet(VectorX(GetThingVel(player)), VectorY(GetThingVel(player)),
      VectorLen(VectorCross(VectorSet(0, 0, VectorZ(GetThingVel(player))), GetThingUVec(player)))
      ),
      VectorScale(GetThingUVec(player), VectorZ(GetThingVel(player))-
      VectorLen(VectorCross(VectorSet(0, 0, VectorZ(GetThingVel(player))), GetThingUVec(player)))
      )
      ));


which was attempting to use VectorCross to scale the Z velocity, with little success.

QM
2004-12-09, 12:45 PM #6
Oh, I think I see what you are trying to do now. (The use of a pulse should have triggered all kinds of alarms for me.)

I had used sector thrusts to provide the gravity effect with the code I posted. You are trying to simulate jumping and landing all within a pulse compensating for the unwanted -z level gravity push, right?

Yeah, Hell Raiser would probably be better at this than I; I have only just begun considering fast pulse methods of simulating forces. :)

:)
2004-12-09, 1:00 PM #7
Ah, I see where we got mixed up... yeah, gravity is both semi-helpful and an annoyance when working with this...

Another thought: I could always Clear the 0x1 physics flag from the player, and use some sort of applied force that uses GetGravity() to fake gravity.

Do you or does anyone out there know how the gravity numebr is applied to a player? Say gravity is 2, how is that 2 applied to the character? I can't use a velocity because it would be constant, and falling is a form of acceleration in JK (isn't it?).

I'll play around with
ApplyForce(player, VectorScale(GetThingUVec(player), -GetGravity()));
and see what I can come up with.

QM
2004-12-09, 1:01 PM #8
There is only a constant level gravity set in the jkl. It defaults to 4.

:)
2004-12-09, 1:03 PM #9
The level gravity is always this vector:
(0, 0, - value in jkl)

If you ClearPhysicsFlag(0x1) on the player thing, the level gravity vector will not be applied to the player thing.

(Funny. I had not noticed the GetGravity verb before QM mentioned it.)

:)
2004-12-09, 1:21 PM #10
Hmm...maybe you could use the code I gave (or your original without the VectorScale/VectorZ stuff), ClearPhysicsFlag(player, 0x1), and use a sector thrust to simulate the gravity that will push the player back to the surface. You wouldn't need the pulse, just set all this when player jumps and reset when he lands.

:)
2004-12-09, 1:59 PM #11
The problem is my code allows the player to rotate freely, so sector thrust would have to be constantly recalculated. Also, is sectorthrust not sync'd in multiplayer, because if it is sync'd, it'd cause lots of network traffic and screw physics in the sector for other players.

The following code works well except once you get past 90 degree angle (to a flat ground) walls/ceilings, then it becomes hard to jump.

SetPulse(0.01);
ClearPhysicsFlags(player, 0x801);
SetPhysicsFlags(player, 0xB0);

are the suggested initialization settings.

Code:
pulse:
   if(!GetThingAttachFlags(player))
   {
      SetThingRotVel(player, VectorSet(
         VectorY(GetThingThrust(player)) * 150,
         VectorY(GetThingRotVel(player)),
         VectorX(GetThingThrust(player)) * (-214.3)
      ));

      if(jumped == 0)
      {
         SetThingVel(player, VectorAdd(
         VectorSet(VectorX(GetThingVel(player)), VectorY(GetThingVel(player)), 0),
         VectorScale(GetThingUVec(player), VectorZ(GetThingVel(player)))
         ));
         jumped = 1;
      }

      ApplyForce(player, VectorScale(GetThingUVec(player), -(GetGravity() * 5.5)));
   }
   else
   {
      SetThingRotVel(player, VectorSet(0, VectorY(GetThingRotVel(player)), 0));
      jumped = 0;
   }
   Return;

The SetThingRotVel code is used to let the player rotate freely.

QM
2004-12-09, 2:10 PM #12
Zeq's been working on this for a while, it's on his hub, I believe. He's been attempting a simulation of a rotating space station. Using sector thrusts for the various gravity, lol. A similar thing was done by HellRaiser I believe for a planet in one of the TDiR levels, though I don't know if it allowed the same type of jumping.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2004-12-09, 2:22 PM #13
As soon as Zeq mentioned using sector thrusts to simulate gravity I remembered him mentioning that elsewhere and I had given his space station alpha version a try (it's what got me working on this). Brilliant minds think alike?

QM
2004-12-09, 2:26 PM #14
Perhaps. As HellRaiser and mysefl were both figuring mouse movement coding at same time, lol...
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2004-12-09, 4:44 PM #15
Lol, I seem to have lots of code laying around on my computer. I really should release it sometime (actually, I should finish it first, but that's another matter).

This script is designed to simulate the downward pull of gravity on the player. If you want to change the direction of gravity, just adjust the vector dir to point in the new direction.

Code:
# MOTS Cog Script
#
# Gravity.COG
#
# Incomplete gravity cog.  Just pulls down.
#
# SG-fan

symbols

message     startup
message     pulse

thing       player                              local

vector      dir					local

flex		gravity=.13				local	//-9.8m/s2
end

# ========================================================================================

code
startup:
dir=VectorSet(0, 0, -1);
sleep(3);
   player = GetLocalPlayerThing();
	ClearPhysicsFlags(player, 0x1);
SetPulse(0.01);
Return;


pulse:
      AddThingVel(player, VectorScale(dir, gravity));
      Return;
end


Now, if the jumping cog is being made for MOTS, you can use the playeraction verb to catch and stop the player from using the engine to jump. However, if this is JK, I don't know how to stop the engine from trying to jump. The only idea I have is to make a new hotkey and tell all players not to use the old jump key.
Sam: "Sir we can't call it 'The Enterprise'"
Jack: "Why not!"
2004-12-09, 5:20 PM #16
Huh? What in the world are you (QM) trying to do? :confused:

I will need a different description if I am ever going to be of help, instead of just slowing you down. ;)

(Wow! The amount of cool stuff editors are working on right now is making me dizzy.)

:)
2004-12-09, 6:10 PM #17
What I'm doing is making a cog, in this case a replacement for IR Goggles, that lets you walk on walls, rotate while in the air so you don't need sloped surfaces to attach to new surfaces (so you can go from floor to a perpendicular wall at any time), jump off of the surface you're attached to as if gravity were pulling you against that wall, and have it to whichever direction is "down" as compared to your orientation is the direction "gravity" pulls you.

And I basically got that all working. The only part that doesn't function quite as I want is jumping if you're exactly upsidedown.

I'm gonna test AddThingVel instead of ApplyForce for simulating gravity.

QM
2004-12-09, 6:35 PM #18
Ah, that makes sense. In other words, the player's *feet* are 'attracted' to the walls.

Sector thrusts would work if you wanted the *walls* to 'attract' (which is what I wanted in my space station level).

What is wrong with the upside-down jumping? I remember having to do something weird to get around problems with exactly that situation (but I was using sector thrusts so it might not be the same problem).

Sounds like fun,
:)

↑ Up to the top!