Hi community,
I’m writing a custom floating monster in zscript. I would like to specify a preferred float height for the monster, eg 64 units.
Does anyone know if this is possible? I have implemented a custom zscript approach but it’s not great.
Preferred Float Height
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
-
-
- Posts: 1845
- Joined: Sun Jul 21, 2019 8:54 am
Re: Preferred Float Height
Could you show your current implementation?
-
- Posts: 3
- Joined: Fri Nov 08, 2024 2:54 am
Re: Preferred Float Height
Apologies - I never saw a notification that someone responded.
Heres the zscript
Code: Select all
override void Tick()
{
super.Tick();
if(bFloat)
{
double targetHeight = floorz + preferredFloatHeight;
if (pos.z < targetHeight - 8) // Allow for a small buffer to prevent jittering
{
vel.z += 2.0; // Move up
}
else if (pos.z > targetHeight + 8)
{
vel.z = -2.0; // Move down
}
else
{
vel.z = 0;
}
}
}
Couple of approaches I have thought about -
- Trying to figure out the next polygon the monster is facing when they try to move
- If the monster can't move, disable my float code with some sort of cooldown logic
-
-
- Posts: 1845
- Joined: Sun Jul 21, 2019 8:54 am
Re: Preferred Float Height
That's about how I would have done it.
Now for what you want to do, I recommend using LineTrace:
Now for what you want to do, I recommend using LineTrace:
Code: Select all
If(target){
FLineTraceData h; //Save LineTrace data to this variable
If(target.pos.z > pos.z){ //If target's position is above the monster's
LineTrace(AngleTo(target),radius*2,0,TRF_THRUACTORS,0,data:h); //Trace a line aimed at the target
If(h.HitType==TRACE_HitWall){vel.z = 2.0;} //If wall was hit, move up
}
Else If(target.pos.z < pos.z){ //Same here but for lower position
LineTrace(AngleTo(target),radius*2,0,TRF_THRUACTORS,height,data:h); //This time I am using the monster's height as the Z offset of the trace to account for ceilings
If(h.HitType==TRACE_HitWall){vel.z = -2.0;}
}
}
-
- Posts: 3
- Joined: Fri Nov 08, 2024 2:54 am
Re: Preferred Float Height
That’s awesome. Thanks I’ll give it a go