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 / Maths/Physics question

Author
Message
Grook
AGK Backer
12
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 17th Jul 2015 19:54
What I'm trying to achieve should be easy, but I can't figure it out - been a long time since I did my pure maths A-level...

So I have a missile like physics object that homes in on the player and it works marvellously apart from one thing - it slows down as it nears the player. I know why this is - the velocity vectors get smaller as the objects get closer but I can't work out how to get a constant velocity towards the player regardless of the distance. I'm doing something like this...


... where ftx & fty are my player position and fmx and fmy are my missle position.

Help a tired-brained eejit out eh?

"It is said that your life flashes before your eyes just before you die. That is true, it's called Life.”
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 17th Jul 2015 23:11
player pos
px
py
missile pos
mx
my
delta
dx=px-mx
dy=py-my
length
l=sqrt(dx*dx+dy*dy)
size 1
dx=dx/l
dy=dy/l
Velocity = direction * value
vx=dx*100.0
vy=dy*100.0

AGK 108 (B)19 + AppGameKit (Steam) V2 Beta .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Grook
AGK Backer
12
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 18th Jul 2015 12:56
Thanks Markus, appreciate the answer. Works like a charm!

"It is said that your life flashes before your eyes just before you die. That is true, it's called Life.”

Login to post a reply

Server time is: 2024-11-16 18:17:55
Your offset time is: 2024-11-16 18:17:55