Cover System Help Needed
by Adam Gardner · in Torque 3D Professional · 10/01/2013 (12:25 pm) · 19 replies
Ok So I have a few questions for a cover system I would love to work out,
First is there a way to just rotate the camera to the other side of the player like in front of him and limit the turn radius?
Also what would be the best way on approaching a check on if your about to run into a wall to start the cover process. Say your walking to a wall and about 5 steps before you collide with the wall you cast a raycast or call a function.
I also need a function or a way to allow the player to move left right and back only when in cover mode.
Thanks for the help!
First is there a way to just rotate the camera to the other side of the player like in front of him and limit the turn radius?
Also what would be the best way on approaching a check on if your about to run into a wall to start the cover process. Say your walking to a wall and about 5 steps before you collide with the wall you cast a raycast or call a function.
I also need a function or a way to allow the player to move left right and back only when in cover mode.
Thanks for the help!
#2
10/01/2013 (1:01 pm)
I would go with triggers before the wall over a ray cast myself. Gives more level design control over what is cover, when you go into cover and all that. Or bind it to a button, so the player can decide if they want to go into cover or not. Similar to how the latest Deus Ex handled it.
#3
https://www.youtube.com/watch?feature=player_embedded&v=pEB_KTKtNsM
and for that when he gets close enough he goes into cover mode.
10/01/2013 (1:08 pm)
Hmm well I'm working on a freelance project for someone and hes wanting something like https://www.youtube.com/watch?feature=player_embedded&v=pEB_KTKtNsM
and for that when he gets close enough he goes into cover mode.
#4
I think that kind of system would give the level designer much more control over when and how the player goes into cover. You don't have to cast any rays, or do any vector math to get facings and what not.
Thats how I would tackle it anyway.
10/01/2013 (2:07 pm)
If you listen to the guy talking and look at the controller mapping he pops up, you use the right button to go into cover. So if you are mimicking GTAV, I would put trigger objects around things you can can take cover behind. When the player enters that trigger, you mark them as being able to take cover and could even have a reference to the object that they can take cover behind. Then when the player hits the cover button, you check if they are in a cover trigger, and if they are, you move them up to the cover and put them in cover animation. Then when they let go of the button, you take them out of cover mode.I think that kind of system would give the level designer much more control over when and how the player goes into cover. You don't have to cast any rays, or do any vector math to get facings and what not.
Thats how I would tackle it anyway.
#5
function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj)
what I see is that even though I get a radius to the triggers location I'm working on finding what tsstatic objects are inside the trigger which one is closer and rotate to the opposite direction the object is to the player but it also seems that when using this it sets my rotation 180 degrees but to the center of the trigger how would I be able to get the radius to the whole object and not just the center location.
10/01/2013 (8:52 pm)
Im stuck on this problemfunction get2DVectorAngle(%vec1, %vec2)
{
%vec1n = VectorNormalize(%vec1);
%vec2n = VectorNormalize(%vec2);
%vec3Perp = getWord(%vec2, 1) SPC (-1 * getWord(%vec2, 0)); // x gets y, y gets -x.
%vdot = VectorDot(%vec1n, %vec2n);
%angle = mACos(%vdot);
%pdot = VectorDot(%vec1n, %vec3Perp);
if (%pdot < 0)
{
%angle *= -1;
}
// convert to degrees and return
%degangle = mRadToDeg(%angle);
return %degangle;
}function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj)
%angle = get2DVectorAngle(%obj.getEyeVector(),VectorSub(%trigger.getPosition(),%obj.getPosition()));
if(%angle < 0){
%objTransform = %obj.getTransform(); //Get Cur Rotation X,Y,Z Loc
%tryRotation = "0 0 0 0 0 1 " @ mDegToRad(0);
%newTransform = matrixMultiply(%objTransform, %tryRotation);
%obj.setTransform(%newTransform);
echo("Angle Less then 0");
}else
{
%objTransform = %obj.getTransform(); //Get Cur Rotation X,Y,Z Loc
%tryRotation = "0 0 0 0 0 1 " @ mDegToRad(180 - %angle);
%newTransform = matrixMultiply(%objTransform, %tryRotation);
%obj.setTransform(%newTransform);
echo("Angle more then 0");
}what I see is that even though I get a radius to the triggers location I'm working on finding what tsstatic objects are inside the trigger which one is closer and rotate to the opposite direction the object is to the player but it also seems that when using this it sets my rotation 180 degrees but to the center of the trigger how would I be able to get the radius to the whole object and not just the center location.
#6
10/02/2013 (4:11 pm)
Any body have an idea?
#7
What do you mean by "the radius to the whole object"?
10/02/2013 (5:58 pm)
Quote:it also seems that when using this it sets my rotation 180 degrees but to the center of the triggerBecause of this:
VectorSub(%trigger.getPosition(),%obj.getPosition())You'll need to find another object other than the trigger. Probably using some sort of container search, though you'd have to be careful filtering the results so you actually got the static shape, not any other objects that may be hanging about nearby.
What do you mean by "the radius to the whole object"?
#8
length from object center position to it's boundary?
radius is only for circular object.
look into:
function getEmptyPlace(%objectToSpawn, %locationTransform,%locationRadius)
there u will find how to do calculation on bounding box.
do some mathmatics to figure out center of the bounding box.
then the radius or whatever u name it.
10/02/2013 (7:28 pm)
"how would I be able to get the radius to the whole object"length from object center position to it's boundary?
radius is only for circular object.
look into:
function getEmptyPlace(%objectToSpawn, %locationTransform,%locationRadius)
there u will find how to do calculation on bounding box.
do some mathmatics to figure out center of the bounding box.
then the radius or whatever u name it.
#9
10/02/2013 (7:40 pm)
well when i do a container search it comes up with the scatter sky for some reason but never the wall which is a TSStatic? and what I mean is that at any spot on the wall I come up to I will rotate until my character is 180 degrees away from the wall that way I am always facing away from it but right now it just seems to only be able to find the center of the object which can be wired when your down the wall some.
#10
As for the centering problem, you're going to have to find the closest point on the cover object's box to your character. This is going to look something like:
10/02/2013 (8:48 pm)
What typemask are you using? Tons of objects like skies unhelpfully share typemasks with objects you might actually be searching for. I usually open up objectTypes.h and do a 'find all references' on each typemask before I use it.As for the centering problem, you're going to have to find the closest point on the cover object's box to your character. This is going to look something like:
- Get position of character in cover's space (requires some sort of matrix transform)
- Get closest point on world box to character pos (google it, shouldn't be too bad)
- Transform closest point back into world space (another matrix op)
#11
Also thanks for the help really appreciate it.
10/03/2013 (2:38 pm)
What would happen to be the function to make your character move to the object but not play the walk animation play a custom one.Also thanks for the help really appreciate it.
#12
This part right here I would thing already get the turn angle on the player to the object but then rotate the player 180 - or + the angle depending on how you approach facing front or back or sideways.
see this way it won't turn just 180 degrees only if its not approaching the object straight on but will turn the rest of the way around depending on his current angle.
10/04/2013 (7:53 am)
Ok it seems I have found the closest object and every thing is working but now when I'm rotating the player I cant seem to figure out how to turn him the remainder degrees up to 180 from the object so the player is turned completely around,%ClosestObj = findsearch(%obj);
echo(%ClosestObj);
if(%ClosestObj)
{
if(%ClosestObj.canCover)
{
%angle = get2DVectorAngle(%obj.getEyeVector(),VectorSub(%ClosestObj.getPosition(),%obj.getPosition()));
echo(%angle);
//
$mvTriggerCount3++;
//
if(%angle < 0){
%objTransform = %obj.getTransform(); //Get Cur Rotation X,Y,Z Loc
%tryRotation = "0 0 0 0 0 1 " @ mDegToRad(180 + angle);
%newTransform = matrixMultiply(%objTransform, %tryRotation);
%obj.setTransform(%newTransform);
echo("Angle Less then 0");
}else
{
%objTransform = %obj.getTransform(); //Get Cur Rotation X,Y,Z Loc
%tryRotation = "0 0 0 0 0 1 " @ mDegToRad(180 - %angle);
%newTransform = matrixMultiply(%objTransform, %tryRotation);
%obj.setTransform(%newTransform);
echo("Angle more then 0");
}
}
}%tryRotation = "0 0 0 0 0 1 " @ mDegToRad(180 + angle);
This part right here I would thing already get the turn angle on the player to the object but then rotate the player 180 - or + the angle depending on how you approach facing front or back or sideways.
see this way it won't turn just 180 degrees only if its not approaching the object straight on but will turn the rest of the way around depending on his current angle.
#13
happens to use the xyz location of the object so the middle of the object and not the point closest to you so I'm assuming if I find the boxes bounding box and use that xy location instead of just the objects it should work correct?
10/04/2013 (8:56 am)
after doing some debugging its actually working as intended but the problem is thisfunction get2DVectorAngle(%vec1, %vec2)
{
%vec1n = VectorNormalize(%vec1);
%vec2n = VectorNormalize(%vec2);
%vec3Perp = getWord(%vec2, 1) SPC (-1 * getWord(%vec2, 0)); // x gets y, y gets -x.
%vdot = VectorDot(%vec1n, %vec2n);
%angle = mACos(%vdot);
%pdot = VectorDot(%vec1n, %vec3Perp);
if (%pdot < 0)
{
%angle *= -1;
}
// convert to degrees and return
%degangle = mRadToDeg(%angle);
return %degangle;
}happens to use the xyz location of the object so the middle of the object and not the point closest to you so I'm assuming if I find the boxes bounding box and use that xy location instead of just the objects it should work correct?
#14
EDIT: I don't believe there's any way to make a Player move with a custom animation. Actually you can probably setActionThread, but it's a little dodgy, at least when I've tried using it with AIPlayers.
Now, if only we had a component system available to us, we could just define our own action animation state machine that behaves however we want...
10/04/2013 (4:14 pm)
Should do!EDIT: I don't believe there's any way to make a Player move with a custom animation. Actually you can probably setActionThread, but it's a little dodgy, at least when I've tried using it with AIPlayers.
Now, if only we had a component system available to us, we could just define our own action animation state machine that behaves however we want...
#15
10/04/2013 (5:15 pm)
Any idea on how to get the bounding box of a TSStatic object and then find the closest point on the object.
#17
10/04/2013 (8:10 pm)
Pretty sure getObjectBox is what you're after.
#18
sorry.i thought he was asking for extent of box.
reading mistake.
ya,to get "bounding box" itself u need to use getObjectBox .
10/04/2013 (9:10 pm)
"Pretty sure getObjectBox is what you're after."sorry.i thought he was asking for extent of box.
reading mistake.
ya,to get "bounding box" itself u need to use getObjectBox .
#19
02/07/2016 (5:07 am)
Has anyone got a working cover system for T3D?
J0linar
and the best way todo this would be to use
meaning if ray hits wall - player goes into covermode aka crouch
as its really not a difference
leaning around corners could/ can be achieved the same way
tbh why would you want the player todo this automaticly
i mean thats like taking away control from the player Oo
a better approach would be simply to check if ray hits wall
allow player to perform covermode
and along with that limit the way the player can move
left/ right
and if front back then player gets out of covermode
i will see if i can come up with some sample script
- no guarantee here