Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (798)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Attack action  (Read 3186 times)
0 Members and 1 Guest are viewing this topic.
Offline steveyg90
« Posted 2017-01-22 19:37:12 »

Hi,

I've implemented attacking in my game but was wondering how you guys go about making a character in your platform game
run and attack the player?

I do it two ways - I use raycast from the bad guy to the player, if they can see them, they head towards them and then start attacking them,
other way is, if player is in close proximity they attack that way.  I do all this via a simple state machine.

Thanks
Offline Catharsis

JGO Ninja


Medals: 76
Projects: 1
Exp: 21 years


TyphonRT rocks!


« Reply #1 - Posted 2017-01-22 21:22:53 »

Check out feedback loops... A good article here page 18.

Check out the TyphonRT Video Suite:
http://www.typhonvideo.com/

Founder & Principal Architect; TyphonRT, Inc.
http://www.typhonrt.org/
http://www.egrsoftware.com/
https://plus.google.com/u/0/+MichaelLeahy/
Offline SteveSmith
« Reply #2 - Posted 2017-01-23 08:01:06 »

I'm not sure if you're talking about deciding when the enemy should attack or how they should get there, but for the former you could use Line-of-Sight, and for the latter use A*, which works just as well for platformers as it does for top-down maps.

Java Multiplayer FPS Engine - https://github.com/SteveSmith16384/SteveTech1
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SkyAphid
« Reply #3 - Posted 2017-01-23 15:26:06 »

I haven't made a 2D platform game, but our 3D game uses similar ideas.

Generally, I program the player/AI to use the same "body" class, so they're both just inserting the same control commands into the same object type. The AI generally spots the player and tries to get close, and will dodge/maneuver in response to player attacks (but doesn't input read! That's cheating).

If it gets the job done and it looks and acts the way you want it to, then it's fine. You don't have to implement something overly fancy just because it's "correct," unless it's harming performance in some way.

it just werks
Offline SHC
« Reply #4 - Posted 2017-01-24 16:52:40 »

I think for simple 2D platformer games, using raycasting is a bit overkill, instead you can get around with a circle with a defined radius of visibility around the area of the player.



(Excuse my poor drawing skills). Any enemy once got a event with circle of visibility, can attack the player and charge towards him. This is more simple in my opinion.

Offline FabulousFellini
« Reply #5 - Posted 2017-01-24 16:54:54 »

@SHC that's also what I do in my game.  I have a rectangle that is larger than the enemy, and if the player intersects with that rectangle, enemy is triggered to attack.

-FabulousFellini
www.fabulousfellini.com
Offline SHC
« Reply #6 - Posted 2017-01-24 17:01:45 »

@SHC that's also what I do in my game.  I have a rectangle that is larger than the enemy, and if the player intersects with that rectangle, enemy is triggered to attack.

You seem to have associating one extra rectangle per each enemy aren't you? I'd instead associate one large rectangle with the player, and if the enemy intersect the large rect, then only that player will rush and attack.

Though both works, it is just an optimization to remove extra shape instances. Even though you went with either way, no penalty will be observed if you have a broadphase that prunes away unnecessary checks.

Offline steveyg90
« Reply #7 - Posted 2017-01-24 20:38:24 »

Thanks all,

Some good suggestions and comments.

I do use ray casting, reason I do is so player can hide behind blocks in my game.  I only draw one line using integer math from the enemy to the player
so it is very quick, if the line hits a block then enemy cannot see the player and thus doesn't go into attack mode.



Pages: [1]
  ignore  |  Print  
 
 

 
Riven (81 views)
2019-09-04 15:33:17

hadezbladez (4337 views)
2018-11-16 13:46:03

hadezbladez (1547 views)
2018-11-16 13:41:33

hadezbladez (4462 views)
2018-11-16 13:35:35

hadezbladez (871 views)
2018-11-16 13:32:03

EgonOlsen (4152 views)
2018-06-10 19:43:48

EgonOlsen (4855 views)
2018-06-10 19:43:44

EgonOlsen (2803 views)
2018-06-10 19:43:20

DesertCoockie (3707 views)
2018-05-13 18:23:11

nelsongames (3998 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!