Results 1 to 21 of 21
  1. #1

    Default Making a boomerang in UDK (Return projectile to player)

    Been trying for awhile to make a boomerang weapon in my game but I can't figure this out!

    I have a pawn, that on keypress calls a function to spawn the boomerang projectile. It goes forward fine, but I need help bringing it back to the player.

    Projectile class:

    Code:
    class Boomerang extends UTProjectile;
    
    var vector InitialLocation; 
    
    function Init(vector Direction)
    {
      SetRotation(rotator(Direction));
    
      Velocity = Speed * Direction;
      Velocity.Z += TossZ;
      Acceleration = AccelRate * Normal(Velocity);
    
      InitialLocation = self.Location;
    
    }
    
    simulated event Tick(float deltaTime)
    {
      local float Distance, MaxDistance; 
      MaxDistance = 300.f;
      
      Distance = VSize(InitialLocation - self.Location);
      
      if (Distance <= MaxDistance){
        
    	} else {
    	 ReturnToPlayer();
      }
      
    }
    
    function ReturnToPlayer(){
      //RETURN CODE GOES HERE
    }
    
    defaultproperties
    {
      Speed=1000
      MaxSpeed=1000
    	
      ProjFlightTemplate=ParticleSystem'Weapon_Boomerang.ParticleSystem.Boomerang'
    }
    Using SetRotation in ReturnToPlayer() does nothing that I can see. Also, I cannot get the player's Location using Instigator.Location, presumably because the projectile is not spawned via a weapon but simply spawned? The player would always have this available while equipped with other weapons so I thought I'd do it this way instead of creating it's own weapon

    Any help would be appreciated! If I could get the projectile to change direction I could go somewhere but I haven't been able to change it's path. Also, this is intended for a 2D viewpoint but I'm sure I could get it working properly if I had a direction to head in. Thanks!

  2. #2
    MSgt. Shooter Person
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    144

    Default

    So ReturnToPlayer() gets called but your having problems getting your boomerang to come back?

    Set rotation will just rotate the boomerang but won't change it's velocity. How about adding an acceleration back towards the player like

    Code:
    Acceleration = AccelRate * Normal(InitialLocation - self.Location);

  3. #3
    MSgt. Shooter Person
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    144

    Default

    Actually using acceleration may end up with the boomerang circling the player and going into orbit if there is any lateral velocity. Change acceleration to velocity and see if that works

  4. #4

    Default

    Quote Originally Posted by paco View Post
    Actually using acceleration may end up with the boomerang circling the player and going into orbit if there is any lateral velocity. Change acceleration to velocity and see if that works
    Thanks for the help paco, that does return the projectile but it's not following the player. If you jump when it's coming back it'll go under you and keep going which isn't good haha

    I appreciate the help!

  5. #5
    MSgt. Shooter Person
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    144

    Default

    Check to see if instigator is None. If you are calling the spawn function from a controller then the location is not what you want - you want the location of it's pawn so instigator.pawn.location may work better.

  6. #6

    Default

    The instigator WAS none, but I couldn't figure out why until I put the spawn call from the Controller to the Pawn class. It returns great after a couple of modifications to the rest of my code! Only problem now is that the boomerang projectile doesn't get destroyed once it collides with the player, how would I check for this?

  7. #7
    MSgt. Shooter Person
    Join Date
    Aug 2010
    Location
    Australia
    Posts
    144

    Default

    Have a look at projectile.uc - in particular these parts:

    Code:
    // Touching
    simulated singular event Touch( Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal )
    {
    	if ( (Other == None) || Other.bDeleteMe ) // Other just got destroyed in its touch?
    		return;
    
    	if (bIgnoreFoliageTouch && InteractiveFoliageActor(Other) != None ) // Ignore foliage if desired
    		return;
    
    	// don't allow projectiles to explode while spawning on clients
    	// because if that were accurate, the projectile would've been destroyed immediately on the server
    	// and therefore it wouldn't have been replicated to the client
    	if ( Other.StopsProjectile(self) && (Role == ROLE_Authority || bBegunPlay) && (bBlockedByInstigator || (Other != Instigator)) )
    	{
    		ImpactedActor = Other;
    		ProcessTouch(Other, HitLocation, HitNormal);
    		ImpactedActor = None;
    	}
    }
    
    simulated function ProcessTouch(Actor Other, Vector HitLocation, Vector HitNormal)
    {
    	if (Other != Instigator)
    	{
    		if (!Other.bStatic && DamageRadius == 0.0)
    		{
    			Other.TakeDamage(Damage, InstigatorController, Location, MomentumTransfer * Normal(Velocity), MyDamageType,, self);
    		}
    		Explode(HitLocation, HitNormal);
    	}
    }

  8. #8
    Redeemer
    Join Date
    Jul 2011
    Location
    London, UK
    Posts
    1,749

    Default

    Mougli made some tutorials that could help here is a sample of his code that you can find in his home page
    http://www.moug-portfolio.info/index...ns-projectiles

    i know it is not the thing you desire exactly but it can help you and make you at least understand how to make a projectile bounce back to you, with this code a little bit of modification would create what you desire
    Code:
    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
    }

  9. #9
    Iron Guard
    Join Date
    Sep 2009
    Location
    England
    Posts
    734

    Default

    I suppose that the first thing you'd want to do is draw a sketch of how you expect that boomerang to behave, post it here. Then we can try to work out a solution.
    Knowledge should be shared with everyone. Technique however, is your own thing.

    My UnrealScript Lessons
    My Blog

    I'm working full-time, so I'm not available for freelance work, sorry.

  10. #10
    Redeemer
    Join Date
    Apr 2010
    Location
    Middle East - Kingdom of Bahrain
    Posts
    1,261

    Default

    Quote Originally Posted by Marcio View Post
    Only problem now is that the boomerang projectile doesn't get destroyed once it collides with the player, how would I check for this?
    Just simply override the ProcessTouch() function like this:

    Code:
    simulated function ProcessTouch(Actor Other, Vector HitLocation, Vector HitNormal)
    {
    	if (Other == Instigator)
    	{
    		Explode(HitLocation, HitNormal);
    	}
                  else
                  {
                                if (!Other.bStatic && DamageRadius == 0.0)
    		{
    			Other.TakeDamage(Damage, InstigatorController, Location, MomentumTransfer * Normal(Velocity), MyDamageType,, self);
    		}
    
                                Explode(HitLocation, HitNormal);
                   }
    }
    Last edited by seenooh; 04-19-2012 at 01:46 PM.
    Hamad Al-Hasan
    Gameplay Programmer / Technical Artist
    Portfolio: http://www.alhasanstudio.com/

    Personal Project: zBioBlow !


    UDK Version: Feb-2013
    OS: Windows 7 Ultimate 64-bit - Service Pack 1
    Intel Core i7 960 3.2 GHz 8MB L3 Cache LGA 1366 130W Quad Core CPU
    12 GB DDR3 Mushkin PC3-12800 998959 (6 x 2048MB) 6-9-7-24 1.65V Blackline
    ASUS Sabertooth X58 LGA 1366 Intel X58 SATA 6Gb/s USB 3.0 ATX Intel Motherboard
    EVGA GTX 580 1.5 GB GDDR5 - Driver Version: 296.10

  11. #11

    Default

    Thanks for the help guys! I already got the return code going awhile ago, can't get collision with the Instigator (the player pawn) working. ProcessTouch doesn't get called when the projectile collides with the player pawn, it DID collide when the exec function that spawns the projectile was in PlayerController, instead of PlayerPawn
    Last edited by Marcio; 04-20-2012 at 08:49 PM.

  12. #12
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Don't set YourPawn as Owner in projectile, Touch can't be triggered...

  13. #13

    Default

    Quote Originally Posted by VendorX View Post
    Don't set YourPawn as Owner in projectile, Touch can't be triggered...
    Projectile's owner is returning None

  14. #14

    Default

    When you spawn the projectile, the second parameter of the spawn function is your owner,
    So make sure to pass the pawn in there.

    Also a simple velocity = normal(owner.location - location) * vize(velocity);
    On the tick will make the projectile return to the pawn.

    Just make sure your touch handles touching the owner properly, and remember that
    You will need to take obstacles into consideration.
    Released Games:
    -Fridge Raider
    -Laser Vault

    Upcoming Titles:
    -Raid
    -Epar

    Demo Reel 2011 (WIP):
    -Demo 2011 (WIP)

  15. #15

    Default

    The pawn being the owner or not doesn't seem to affect collision, it doesn't seem to call ProcessTouch in either case

  16. #16
    Redeemer
    Join Date
    Apr 2010
    Location
    Middle East - Kingdom of Bahrain
    Posts
    1,261

    Default

    If ProcessTouch() didn't help, try Hitwall().
    Hamad Al-Hasan
    Gameplay Programmer / Technical Artist
    Portfolio: http://www.alhasanstudio.com/

    Personal Project: zBioBlow !


    UDK Version: Feb-2013
    OS: Windows 7 Ultimate 64-bit - Service Pack 1
    Intel Core i7 960 3.2 GHz 8MB L3 Cache LGA 1366 130W Quad Core CPU
    12 GB DDR3 Mushkin PC3-12800 998959 (6 x 2048MB) 6-9-7-24 1.65V Blackline
    ASUS Sabertooth X58 LGA 1366 Intel X58 SATA 6Gb/s USB 3.0 ATX Intel Motherboard
    EVGA GTX 580 1.5 GB GDDR5 - Driver Version: 296.10

  17. #17

    Default

    HitWall gets called when the projectile collides with, well, walls. Like the middle square in the default map, for example. Doesn't get called on the player pawn though. Nothing seems to get called when I spawn the projectile in the PlayerPawn class, but if I spawn it in the PlayerController class it collides fine. Should I just spawn it from the controller? Not really sure why it'd work from Controller but not Pawn, if the Owner in both instances is both None. Only difference is that in controller the instigator is also set to none
    Last edited by Marcio; 04-21-2012 at 03:57 PM.

  18. #18

    Default

    K process touch is a projectile function, i rather script my projectiles from actor.

    See the projectile class has a lot of stuff u really dont need.

    So on a basic class that extends actor you need,
    Bstatic false
    Bcollideactors true
    Bcollideworld true
    A simple cylynder component as your collision comp
    Physics phys_projectile
    A mesh to show or particle system

    And u use touch and hitwall events to do what u need.

    Anything else just seams like overkill
    Released Games:
    -Fridge Raider
    -Laser Vault

    Upcoming Titles:
    -Raid
    -Epar

    Demo Reel 2011 (WIP):
    -Demo 2011 (WIP)

  19. #19

    Default

    Well i got inspired to try it. Seams the pawn wont call the touch or hitwall events. It could have something to do with the blockedbyinstigator thing but not sure, will atempt that.
    Just in case what i did was create a check pawn by checking the
    Touching actors and returning the pawn. Then i check on tick but i had to use
    Setlocation(location);
    To ensure the touchingactors array is not empty
    Released Games:
    -Fridge Raider
    -Laser Vault

    Upcoming Titles:
    -Raid
    -Epar

    Demo Reel 2011 (WIP):
    -Demo 2011 (WIP)

  20. #20

    Default

    Yeah, I'm not sure what I'm doing wrong. As far as I know ProcessTouch should be getting called...

  21. #21
    MSgt. Shooter Person
    Join Date
    Feb 2012
    Posts
    47

    Default

    Quote Originally Posted by Marcio View Post
    Yeah, I'm not sure what I'm doing wrong. As far as I know ProcessTouch should be getting called...
    What about spawning a projectile and sending it to the target and once it hits the target it despawns like usual.

    As soon as it hits target, spawn another projectile with insane target homing that is fired at the player from the hit target, but has neutered damage and momentum.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.