Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sprite following another sprite and sprite image angle towards the other sprite question.

Author
Message
Midget Blaster
AGK Developer
8
Years of Service
User Offline
Joined: 7th May 2016
Location:
Posted: 31st Aug 2016 21:47
Hey, so my attempt at making a top down shooter is both amazing and a catastrophically failure. Right now with my limited knowledge I am trying to add a zombie following the player, which works properly but not really, and the zombie to aim at the player.


This is my attempt at a function that allows a sprite to follow another one.


The zombie follows the player, but only vertically and horizontally, and diagonally


It follows the player, but since it follows it in those directions only it is very easy to run away from and not challenging at all. Any tips on how to improve this?

As for getting the zombie to aim at the player, in between the


I have added setspriteangle(zombie,?), with the ? corresponding to the direction it is heading, so 90 heading right, 135 heading diagonally but that is not going to work with new code.

Thanks guys, You're the best help I can get in agk

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 31st Aug 2016 23:08
maybe u can make and use a position list.
see / hear or smell, means leave a trail, also calculate where the player is in the next seconds in relation the zombie can walk this way.


AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 31st Aug 2016 23:12 Edited at: 31st Aug 2016 23:16
To get the angle between the zombie (z) and the player (p), use atanfull. Then you can rotate the zombie sprite according to that angle.



Then to move your zombie in that direction, use this formula:



Once you've got that, you can work on doing curved values. What those do is gradually shift between angles rather than jump straight to it. Think of the turn radius of a car. They don't turn left or right immediately. They sort of drift towards that angle until the desired angle for the turn is achieved.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 1st Sep 2016 08:00
Getting the zombie to rotate and move towards the player is the most basic solution but makes the zombie appear unintelligent (perfect for a zombie I suppose!).
If you want a more intelligent approach then you need to predict where the player is about to be and move towards that point instead.

This page on Steering Behaviours and those associated with it will help a lot - especially if you intend to have multiple enemies 'flocking' towards the player.


AGK V2 user - Tier 1 (mostly)
Midget Blaster
AGK Developer
8
Years of Service
User Offline
Joined: 7th May 2016
Location:
Posted: 1st Sep 2016 17:40
Thank you @phaelax! I had to change it up a tiny bit.


I had to make the speed negative in the first one. Also, because my zombie sprite when making it, it has his arms pointing down and went towards me with his back turned. So i simply fixed it by doing


@scraggle Thank you for linking that website. Even though the code there is c++ or javascript, I can still learn and incorporate form other languages somehow into AGKBASIC
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Sep 2016 14:14
Quote: "This page on Steering Behaviours and those associated with it will help a lot - especially if you intend to have multiple enemies 'flocking' towards the player."

That's a really good page, I just read the whole article! Loads of great stuff in there giving me ideas!
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 2nd Sep 2016 15:28
Quote: "Even though the code there is c++ or javascript"
It's Actionscript.
Quote: "That's a really good page"

If you want more like that then do a Google search for Craig Reynolds. Everything I have read on steering behaviours references his work.
AGK V2 user - Tier 1 (mostly)
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Sep 2016 01:34
This:
zx# = zx# + sin(angle)*-1
zy# = zy# + cos(angle)*1

Is the same thing as simply saying this:

zx# = zx# - sin(angle)
zy# = zy# + cos(angle)

You don't need the extra multiplication.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-11-25 03:44:59
Your offset time is: 2024-11-25 03:44:59