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.

Author
Message
BeastDeath
15
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 20th May 2012 23:01 Edited at: 20th May 2012 23:03
Hello everyone, I was wondering how I'd make the current code (credit to hodgey) to always go forward from the position? WITHOUT using any of the dark automatic functions such as move object or move sprite?

An example would be that the point the object needs to travel is at a mouse cursor position, but it needs to keep going forward like a bullet.



zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 20th May 2012 23:58
Not sure if you mean that the red circle should always be at the mouse cursor's position, or if the red shape should move towards the mouse cursor's position.

The former would be something like this:


Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 21st May 2012 06:06
Hi there
Like zeroSlave, I can't figure out what you mean with keeping going forward like a bullet. Your piece of code use a function that increase or decrease x,y values to follow the other circle....here you don't use any command to point from one object to the other. You can do it using newxvalue, newyvalue depending on an given angle.




Cheers.

I'm not a grumpy grandpa
BeastDeath
15
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 21st May 2012 09:35 Edited at: 21st May 2012 09:36
What I mean is, if I clicked once on the screen, the circle will go to that position as well as continuing in the same direction to keep going like a bullet would, this could be easily achieved with move sprite or move object but how would I do it with the maths like above?
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 21st May 2012 14:16
Like chafari pointed out, the commands you need are:

newxvalue
newzvalue


So the new positions of the bullet can be calculated by:



TheComet

BeastDeath
15
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 21st May 2012 22:55
Thanks for the help everybody, but how would I do this without using any automatic functions? I want to use only maths such as COS, TAN etc?
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 22nd May 2012 01:49
I can't remember which way around it is, but the new_value commands are equivalent to sin/cos:

newxvalue( Current# , Angle# , Speed# )
newzvalue( Current# , Angle# , Speed# )

are equivalent to (order/signs may be wrong):

Current# + sin(Angle#)*Speed#
Current# + cos(Angle#)*Speed#

[b]
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 22nd May 2012 10:50 Edited at: 22nd May 2012 11:16
Take a look at this code:


It's a little movable turret that shoot towards the mouse cursor. If the bullet's velocity does not change, you would only need to use sin/cos/atan when the bullet is created which would save some resources. The math you'll use and the data you'll want to store is:


Then you can move the bullet by adding its 'speed' to it's current position:


Then to draw it:


Hope this helps.

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
BeastDeath
15
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 23rd May 2012 15:50
Just what I was looking for, thanks everyone for the help

Login to post a reply

Server time is: 2026-07-22 00:35:46
Your offset time is: 2026-07-22 00:35:46