Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am fairly new to the programming world. I am currently at College and one of the tasks I need to do is create a "stun gun" or "freeze gun". Basically when you shoot a target (other player) i want it to stop them for 5 or so seconds, The gun will do no damage to the player, just simply freeze them. The player can be refrozen and/or continuously shot to remain frozen until the shooters ammo runs out. This may sound weird but its for a certain game-type i am making. If anyone can give me some help on what to call in certain classes, or even provide me with the basic code the will freeze the player for several seconds, ill be very thankful.

I know how to make a new weapon, and change fire-rates etc... I am just stuck with what it is i have to do to freeze a player using the projectile class, or pawn class?

share|improve this question
    
Sorry for those who want to know the version of udk I am currently using, it is: UDK-2015-01 –  Matthew Sinclair Jul 17 at 7:14
1  
The player needs a frozen timer variable. If the variable is above 0 decrease it by Delta time. When you hit a player with the weapon, you need to set the frozen timer variable to the number of seconds you want them to be frozen.. Lastly, before any player movement, you have to make sure the freeze variable is 0 or lower. If not, don't move –  Daniel Holst Jul 17 at 9:49
    
Ah yes, Thank-you. But Do you know how to code this? Cause I still cant figure it out. –  Matthew Sinclair Jul 17 at 10:04
1  
Coding should really be your job otherwise you are going to ask the exact same question on your next homework assignment. @DanielHolst nailed it for you. On hit you increase the frozen timer of the player it hits. You do not move the player until the frozen timer hits <= 0 again. –  Menno Gouw Jul 17 at 14:07
    
Other then that you could ask or google how to effect a variable of a target hit by a gun which in UDK I do not know the answer about. Now you should know how to increase a variable like int freezeTimer on a player by getting shot. If you made a good attempt but still have undesired behavious then you can post your issue including code and people here are much more willing to do a bit of coding for you and help you on your way. –  Menno Gouw Jul 17 at 14:12

1 Answer 1

up vote 0 down vote accepted

Ok I decided to help you on your way. But we are simply not doing homework for you. UDK documentation seems down for maintainance but I have found this: http://www.moug-portfolio.info/udk-projectiles/ example. You should read it completely since it helps you understand projectiles. Towards the bottom they explain projectiles. Let it be clear that I have no experience other then creating some simple maps a decade ago with UDK.

The code I found on the mentioned website that I will be discussing:

class SandboxPaintballProjectile extends UDKProjectile;

simulated function ProcessTouch(Actor Other, Vector HitLocation, Vector HitNormal)
{
    if ( Other != Instigator )
    {
        WorldInfo.MyDecalManager.SpawnDecal ( DecalMaterial'SandboxContent.Materials.DM_Paintball_Splash', HitLocation, rotator(-HitNormal), 128, 128, 256, false, FRand() * 360, none );
        Other.TakeDamage( Damage, InstigatorController, Location, MomentumTransfer * Normal(Velocity), MyDamageType,, self);
        Destroy();
    }
}

simulated event HitWall(vector HitNormal, actor Wall, PrimitiveComponent WallComp)
{
    Velocity = MirrorVectorByNormal(Velocity,HitNormal); //That's the bounce
    SetRotation(Rotator(Velocity));
    TriggerEventClass(class'SeqEvent_HitWall', Wall);
}

DefaultProperties
{
    Begin Object Name=CollisionCylinder
        CollisionRadius=8
        CollisionHeight=16
    End Object

    Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
        bEnabled=TRUE
    End Object

    Components.Add(MyLightEnvironment)

    begin object class=StaticMeshComponent Name=BaseMesh
        StaticMesh=StaticMesh'SandboxContent.Meshes.SM_PaintBall'
        LightEnvironment=MyLightEnvironment
    end object

    Components.Add(BaseMesh)

    Damage=25
    MomentumTransfer=10
}

My first assumption is that if you create a weapon with a projectile you have this script attached to it. I simply cannot help you with that.

As Mougli talks about this he explains that if a wall or actor with bWorldGeometry set to true the HitWall function/method will be triggered. Since we are not freezing walls or furniture we will leave that alone. Whenever another actor get's hit the ProcessTouch is being called and like I already mentioned you are supplied by the actor that actually is hit Actor other.

Now we can call that actor and do stuff with it by doing other.doStuff. So we want to increment a freeze variable? Then we need to supply this variable first too this actor. So first we need the script actor script.

Let's assign a variable public int freezeCounter = 0f on top.

Now we can access that variable from the ProcessTouch method and alter it. other.freezeCounter = 2000 in milliseconds. Whenever an actor is hit he gets his freezeCounter set to 2000.

Now we need to make sure the actor is not able to move. We could wrap all the actors actions in a if statement stating if (freezeCounter <= 0) and he will be frozen for it's entire life. The last step is to decrease the freezeCounter by the amount of miliseconds since the last frame often called something like deltaTime.

The best lesson you should learn from this is to break down your problem into small steps. Try to define these steps and look around on Google for answers, like I did for the Projectile Collision.

However there might be a view catches. I'm not sure what the definition of actor is in UDK but basically anything that can be hit seems to be an actor. You might have to check in the ProcessTouch method if an actualy player or character has been hit. Again I do not know the naming conventions but if you open a players script and it says something like class Character extends Actor then you can add the variable to the Player script. But then you will not be able to use other.freezeCounter = xxxx. Now you need to cast it:

if (other instanceof Character) //check if the actor is a character { (Player)other.freezeCounter = 2000; //cast other as a player and alter freezeCounter }

This should get you on your way, otherwise I strongly suggest you tell your teacher to learn you the basics of programming first before telling you to code in a engine you barely know and afaik is pretty much obsolete (could be wrong on my last statement).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.