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 → Collide with a Twist
Collide with a Twist
2005-02-22, 12:08 PM #1
Hi!
I'm just wondering, How am I to make the following template Collide with surfaces and objects other than actors and weapons, and with the parent (player who created), yet not get in its way (it won't slow me down if I collide, I can easily push it out of my way as if it was air).

Code:
+cam		none			orient=(0.000000/0.000000/0.000000) type=cog model3d=rpt0.3do collide=0 size=0.0001 movesize=0.0001 move=physics vel=(0/0/0) angvel=(0/0/0) mass=1 staticdrag=1 thingflags=0x810 physflags=0x400226 surfdrag=1 airdrag=10


/Edward
Edward's Cognative Hazards
2005-02-22, 3:24 PM #2
Maybe you could set some of the drag params lower.
If that doesn't work, you could try adding this class cog to your template. I've tested it on the bryarbolt and it works, but I haven't tried it on a pushable object, b/c I have to go eat dinner now...
Code:
# Simulation of drag
# [darthslaw]

symbols

vector	vel		local
thing	obj		local
flex	v		local

flex	dv=1.5		local	#change in velocity _per_second_
flex	pulserate=0.1	local	#the smaller this number, the smoother the decline in velocity

message	created
message	pulse

end
code
created:
	print("created");
	SetThingPulse(GetSenderRef(), pulserate);

return;
pulse:
	obj = GetSenderRef();
	vel = GetThingVel(obj);
	v = VectorLen(vel);
	if(v > 0)					//moving
	{
		printflex(v);
		v = v - (dv * pulserate);		//decrease velocity
		if(v < 0) v = 0;			//friction will stop the object, not reverse direction
		vel = VectorScale(VectorNorm(vel), v);	//calculate decreased velocity
		SetThingVel(obj, vel);			//Set Decreased Velocity
	}
	
return;

end
May the mass times acceleration be with you.
2005-02-22, 7:35 PM #3
move=physics, lower staticdrag, airdrag, surfdrag and mass significantly. Surf drag is essentially the coefficient of static friction in physics, against the floor... The air drag is friction against air, and in JK static drag is listed natural resistance to forces, apparently, but I'm guessing it's coefficient of static friction, while surf drag is moving friction. (Static friction determines how much force is needed to start something moving) (Movement friction is how much the force is lessened while something is moving... if I remember things correctly). Anyways, what it comes down to, is (mass * gravity * coefficient) is the force against whatever's pushing it... I think. Physics seems so long ago. So, you want it to move lightly, set mass and the drags low... Someone correct me on physics, as I imagine I screwed up.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2005-02-22, 8:29 PM #4
Looks to me like you got it right sniperwolf. Pat yourself on the back for remembering stuff from a while back :)

btw, if anyone uses my cog for anything, I forgot to mention that I assume all drag values are set to 0. if they aren't, I'd guess that your object will slow down faster, but I haven't experimented at all there.
May the mass times acceleration be with you.
2005-02-25, 8:04 AM #5
OK, I decreased the Mass and Staticdrag considerably (0.001), but it is still in my way. And I haven't decreased the airdrag. I tested with just these 2 to see where I was, and my camera (which is being moved by a cog) went all over the place! And so, I'm not sure how much more I can decrease the speed, or what the stopping distance will be. And the SurfDrag, I want some resistance when it hits a surface.

Code:
+cam		none			orient=(0.000000/0.000000/0.000000) type=cog model3d=rpt0.3do collide=1 size=0.0001 movesize=0.0001 move=physics vel=(0/0/0) angvel=(0/0/0) mass=0.001 staticdrag=0.001 thingflags=0x810 physflags=0x400226 surfdrag=1 airdrag=10


/Edward
Edward's Cognative Hazards
2005-02-25, 8:56 AM #6
You didn't listen to what SurfDrag is. That's the prob. Surf drag is essentially the coefficient of dynamic friction. After the object is started moving, by overcoming staticDrag, SurfDrag determines how much a force put on it is lessened. Actually running into a surface has absolutely nothing to do with this variable, as that wouldn't be drag, but a collision factor in regards to a surface. These drag coefficients basically state how hard it is to get an object moving, and keep it moving.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2005-02-25, 9:34 AM #7
OK... diminissed SurfDrag, and still a problem... Diminished AirDrag and the camera went erverywhere but where I wanted it. I decrease the move values, and then it can't keep up with me.

/Edward
Edward's Cognative Hazards
2005-02-25, 12:31 PM #8
Hmm, I think you should post the cog and what you're wanting exactly. Didn't read the part about the camera, so yeah, what's this supposed to be doing...
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2005-02-25, 1:45 PM #9
OK. I've changed things a little bit after figuring things out for myself, but basically I want the camera to move as it does now, only with the addition of that it doesn't collide with Actors or Weapons.

Code:
# New Camera View. More advanced. I think.
#
# By Edward
flags=0x240
symbols

message		startup
message		pulse
message		timer
message		killed

thing		cam		local
template	camera=+cam	local
thing		player		local
template	aim=+aim	local

thing		behindp		local
vector		lv		local
vector		lvr		local
vector		npos		local
int		fall=0		local

flex		place		local

end
#
code
startup:
	player=GetLocalPlayerThing();
	cam=FireProjectile(player,camera, -1,-1, '0 0 0','0 0 0', 0,0,0,0);
	CaptureThing(cam);
	fall=0;
	SetPulse(0.01);
return;
pulse:
	FireProjectile(player,aim, -1,-1,'0 0 0.037','0 0 0', 0,0,0,0);
	behindp=FireProjectile(player,camera, -1,-1, '0 -.1 .05','0 0 0', 0,0,0,0);
	place=1.5;
	if(GetSectorFlags(GetThingSector(player)) & 0x1)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp = FirstThingInSector(GetThingSector(player));
		place=0.05;
	}
	if(GetSectorFlags(GetThingSector(player)) & 0x2)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp=FireProjectile(player,camera, -1,-1, '0 -.1 0','0 0 0', 0,0,0,0);
		place=2;
	}
	if(GetSectorFlags(GetThingSector(player)) & 0x4)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp=CreateThingAtPos(cam, GetThingSector(player), GetSectorCenter(GetThingSector(player)), '0 0 0');
		place=.1;
	}
	if(GetSectorFlags(GetThingSector(player)) & 0x8)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp=FireProjectile(player,camera, -1,-1, '0 0 0','0 0 0', 0,0,0,0);
		place=3;
	}
	if(GetSectorFlags(GetThingSector(player)) & 0x40)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp=CreateThingAtPos(camera, GetThingSector(player), GetSectorVertexPos(GetThingSector(player), 0), '0 0 0');
		place=0.01;
	}
	lv=VectorSub(GetThingPos(cam), GetThingPos(player));
	lvr=VectorSet(-VectorX(lv), -VectorY(lv), -VectorZ(lv));
	SetThingLook(cam,lvr);
	if(behindp!=-1)
		npos=VectorSub(GetThingPos(cam), GetThingPos(behindp));
	else
		npos=VectorSub(GetThingPos(cam), GetThingPos(player));
	if(VectorDist(GetThingPos(cam), GetThingPos(behindp))>.05)
	{
		ApplyForce(cam, VectorScale(VectorSet(-VectorX(npos), -VectorY(npos), -VectorZ(npos)),place));
	}
	if((VectorDist(GetThingPos(cam), GetThingPos(behindp))>1) || (VectorDist(GetThingPos(cam), GetThingPos(player))<.1))
	{
		SetCollideType(cam,0);
	}
	else
	{
		SetCollideType(cam,1);
	}
	DestroyThing(behindp);
	if((GetActorFlags(player) & 0x400000) && (fall==0))
	{
		fall=1;
		SetTimerEx(1.5,player,cam,0);
	}
	if(GetCurrentCamera()==0)
	{
		TeleportThing(cam,player);
	}
	SetCameraFocus(1,cam);
return;
timer:
	if(GetSenderID()!=player) return;
	SetPulse(0);
	SetCameraFocus(1,GetSenderID());
	DestroyThing(GetParam(0));
return;
killed:
	if(GetSenderRef()!=player) return;
	SetPulse(0);
	SetCameraFocus(1,GetSenderRef());
	DestroyThing(cam);
return;
end

Code:
+cam		none			orient=(0.000000/0.000000/0.000000) type=cog model3d=rpt0.3do collide=1 size=0.0001 movesize=0.0001 move=physics vel=(0/0/0) angvel=(0/0/0) mass=1 staticdrag=1 thingflags=0x810 physflags=0x400AE6 surfdrag=1 airdrag=10

Now, I have another problem or 2. When the player enters water sector (0x2) the camera won't move and follow the player. And I'd like to test weather or not the player is attached to an elevator, so I can set the camera in a special way so it is not under the elevator when going up, and not too far away when going down. Or if it is a transport or something that is moving, set a new camera angle. Somewhere along the lines of If(IsMoving(GetThingAttachedToThing(player))) if there is such a thing...

/Edward
Edward's Cognative Hazards
2005-02-27, 3:52 PM #10
Can't anyone help me? Am I asking too much from JK?
Edward's Cognative Hazards
2005-03-02, 2:30 AM #11
Hello?
Edward's Cognative Hazards
2005-03-02, 9:07 AM #12
When I get a bit of free time, I'll work on it. I've been busy. I'll do my best to fix it up though for you.
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come
2005-03-04, 12:12 PM #13
I hump.
Edward's Cognative Hazards
2005-03-06, 2:02 AM #14
(I had posted this in your original thread on the main editing forum, but I guess you never saw it. :p )

To make it not affect the parent, you'll have to make it type=weapon, add typeflags=0x1, and use FireProjectile() to create it. There's no way to make it not collide with things, and still have it collide with surfaces. (unless there's some unknown flag out there...)

To get it to move out of the way (In the event something collides with it) I'd say you need to make it's mass veeeery tiny so that a Thing with a larger mass can just shove it out of the way. You'll have to play around with Mass and the Drags to get a good feel going on. Nobody has really documented much about the physics of JK, and I don't know much myself. ZeqMacaw might know tho. ;)
-Hell Raiser
2005-03-06, 7:09 AM #15
Well, you see, I want it to collide with the player, but still not get in its way.
And I have tried the low values of the Mass and Drags and things didn't work out properly (as was said in this topic). Too slow, too much.
Edward's Cognative Hazards
2005-03-06, 12:10 PM #16
How about adding touched: to your class cog, and when touched, you ApplyForce() it out of the way?
-Hell Raiser
2005-03-06, 1:00 PM #17
Hm... You might be getting at something... I think that it will still slow down the player a bit, but... Hm... If the cam can have 2 Cogs on it (CaptureThing and ClassCog), then maybe...
Change to powerup! It won't get in the way, but will still recieve touched from the player, and will collide with level surfaces! Though, the things might be a prob... Or maybe not... I don't know... Those who have tested my MADMOD might know about the powerups that have full physics. If only they could not go through objects of type COG.

Anyway, I got inspiration. Hell, thanks! The keyword was 'touched'. I might work on something, but if SniperWolf beats me to it, then OK. But I will post if I get something done. Right now, I've gotten another project on my hands. My own URU shard.

/Edward
Edward's Cognative Hazards
2005-03-11, 11:21 AM #18
OK. I did something quick, but it doesn't seem to be working right... And there is still the thing about the water...

Code:
# New Camera View. More advanced. I think.
#
# By Edward
flags=0x240
symbols

message		startup
message		pulse
message		timer
message		killed

thing		cam		local
template	camera=+cam	local
thing		player		local
template	aim=+aim	local

thing		behindp		local
vector		lv		local
vector		lvr		local
vector		npos		local
int		fall=0		local

flex		place		local
thing		x		local
int		vert		local
flex		vertdist	local
int		i		local

end
#
code
startup:
	player=GetLocalPlayerThing();
	cam=FireProjectile(player, camera, -1, -1, '0 0 0', '0 0 0', 0, 0, 0, 0);
	CaptureThing(cam);
	fall=0;
	SetPulse(0.01);
return;
pulse:
	FireProjectile(player, aim, -1, -1, '0 0 0.037', '0 0 0', 0, 0, 0, 0);
	behindp=FireProjectile(player, camera, -1, -1, '0 -.1 .05', '0 0 0', 0, 0, 0, 0);
	place=1.5;
	if(GetSectorFlags(GetThingSector(player)) & 0x1)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp=FirstThingInSector(GetThingSector(player));
		place=0.05;
	}
	if(GetSectorFlags(GetThingSector(player)) & 0x2)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp=FireProjectile(player, camera, -1, -1, '0 -.1 0', '0 0 0', 0, 0, 0, 0);
		place=2;
	}
	if(GetSectorFlags(GetThingSector(player)) & 0x4)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp=CreateThingAtPos(cam, GetThingSector(player), GetSectorCenter(GetThingSector(player)), '0 0 0');
		place=.1;
	}
	if(GetSectorFlags(GetThingSector(player)) & 0x8)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp=FireProjectile(player, camera, -1, -1, '0 0 0', '0 0 0', 0, 0, 0, 0);
		place=VectorLen(GetThingVel(player));
	}
	if(GetSectorFlags(GetThingSector(player)) & 0x40)
	{
		if(behindp!=-1) DestroyThing(behindp);
		behindp=CreateThingAtPos(camera, GetThingSector(player), GetSectorVertexPos(GetThingSector(player), 0), '0 0 0');
		place=0.01;
	}
	lv=VectorSub(GetThingPos(cam),GetThingPos(player));
	lvr=VectorSet(-VectorX(lv), -VectorY(lv), -VectorZ(lv));
	SetThingLook(cam, lvr);
	if(behindp!=-1)
		npos=VectorSub(GetThingPos(cam), GetThingPos(behindp));
	else
		npos=VectorSub(GetThingPos(cam), GetThingPos(player));
	if(VectorDist(GetThingPos(cam), GetThingPos(behindp))>.05)
	{
		ApplyForce(cam, VectorScale(VectorSet(-VectorX(npos), -VectorY(npos), -VectorZ(npos)), place));
	}
	if((VectorDist(GetThingPos(cam),GetThingPos(behindp))>1) && ( !(GetSectorFlags(GetThingSector(player)) & 0x1) || !(GetSectorFlags(GetThingSector(player)) & 0x4) || !(GetSectorFlags(GetThingSector(player)) & 0x40) ))
	{
		SetCollideType(cam,0);
		if(GetSectorFlags(GetThingSector(player)) & 0x40) return;
		vertdist=1.00000000;
		for(i=0; i<GetNumSectorVertices(GetThingSector(player)); i=i+1)
		{
			if(VectorDist(GetSectorVertexPos(GetThingSector(player), i),GetThingPos(player))<vertdist)
			{
				vert=i;
				vertdist=VectorDist(GetSectorVertexPos(GetThingSector(player), vert), GetThingPos(player));
			}
		}
		x=CreateThingAtPos(camera, GetThingSector(player), GetSectorVertexPos(GetThingSector(player), vert), '0 0 0');
		TeleportThing(cam,x);
		DestroyThing(x);
	}
	else if(VectorDist(GetThingPos(cam), GetThingPos(player))<.1)
	{
		SetCollideType(cam,0);
	}
	else
	{
		SetCollideType(cam,1);
	}
	DestroyThing(behindp);
	if((GetActorFlags(player) & 0x400000) && (fall!=1))
	{
		fall=1;
		KillTimerEx(1);
		KillTimerEx(0);
		SetTimerEx(1.5,0,cam,player);
	}
	if(GetCurrentCamera()==0)
	{
		TeleportThing(cam,player);
	}
	SetCameraFocus(1,cam);
return;
timer:
	if(GetParam(0)!=player) return;
	if(GetSenderID()==0)
	{
		KillTimerEx(1);
		if(IsMulti()) return;
		fall=0;
		SetPulse(0);
		SetCameraFocus(1,GetSenderID());
		DestroyThing(GetParam(0));
	}
return;
killed:
	if(GetSenderRef()!=player) return;
	if(IsMulti()) return;
	SetPulse(0);
	SetCameraFocus(1,GetSenderRef());
	DestroyThing(cam);
return;
end

Code:
# Class Cog to Cam
#
# By Edward
symbols

message		created
message		touched

thing		c	local

end
#
code
created:
	c=GetSenderRef();
return;
touched:
	if(GetSourceRef()==GetThingParent(c))
	{
		ApplyForce(c, VectorScale(GetThingLVec(GetSourceRef()), VectorLen(GetThingVel(GetSourceRef()))));
	}
	else if(GetThingType(GetSourceRef())==7)
	{
		StopThing(c);
	}
return;
end

It still goes through things of type cog, and it doesn't seem to move in my direction when I touch it. And I did change the type to item.

/Edward
Edward's Cognative Hazards
2005-03-11, 4:08 PM #19
It's almost what I had in mind, but ApplyForce is not done in JKU's per second. I'm unsure of high enough values when calculating mass and drag and stuff, but you might just want to use a static number, like 100. Also, the direction, just didn't make sense to me. :)

I would write it like so:

Code:
# JK Cog
#
# Move a camera away from a thing that touches it
#
# Tweak the variable 'Force' to
# change the ammount of Force Applied
#
# Created By Hell Raiser [Jon]

symbols

int			Force=100		local

message		touched

end

code

touched:

	Cam=GetSenderRef();
	Toucher=GetSourceRef();
	//Go away from the thing we touch
	Direction=VectorSub(GetThingPos(Cam), GetThingPos(Toucher));
	ApplyForce(Cam, VectorScale(VectorNorm(Direction), Force));

return;

end


Any questions? [http://www.hellraiser64.com/tdir/forums/images/smiles/cheer.gif]
-Hell Raiser
2005-03-13, 1:54 AM #20
Well, the direction... It is the direction of the player at the player's speed. But yours didn't seem to work either.
I did a little print test on mine to see if I was beeing touched. Odd thing. I was being touched constantly! Even though I was 3-4 meters away from the cam! It kept on saying "touched" (print right under touched:) and "player" (print right under ==GetThingParent(c)). It kept on saying so even when it hit a COG type thing. And it did not move at all. Even with your code piece.
Code:
# Class Cog to Cam
#
# By Edward
# Help from Hell Raiser [Jon]
symbols

message		created
message		touched

thing		c	local

vector		d	local

end
#
code
created:
	c=GetSenderRef();
return;
touched:
	print("touched");
	if(GetSourceRef()==GetThingParent(c))
	{
		print("player");
		d=VectorSub(GetThingPos(c), GetThingPos(GetSourceRef()));
		ApplyForce(c, VectorScale(VectorNorm(d), 100));
	}
	else if(GetThingType(GetSourceRef())==7)
	{
		print("else");
		StopThing(c);
	}
return;
end

/Edward
Edward's Cognative Hazards
2005-03-13, 8:06 PM #21
Hmmm, try upping the value of apply force to 1000.
-Hell Raiser
2005-03-14, 1:12 PM #22
Didn't help... And the thing is that it keeps on saying touched player even though I'm more than 2 meters away from the cam. I don't think it is touching what I want it to touch.
Edward's Cognative Hazards

↑ Up to the top!