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
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 22nd May 2014 00:28 Edited at: 22nd May 2014 16:19
So I'm trying to shoot lazers in the direction a spaceship is pointing. Got that done... Although, I'm having trouble getting the positioning of the spawnpoint right and the speed. Here's some code:

Lazer setup:

Lazer spawn:


Some information:
SP_Ship[2].Sprite is the gun sprite. (I build the players spaceship in parts.)
The gun sprite is positioned at a certain point on the ship and then given a offset so that it can rotate around the center point (the middle of the screen). It is positioned like this:
(SP_Ship[1].Sprite is the cockpit in the middle.) Setting the offset:


Rotating the entire ship. (within a for/next loop)
(X# = GetPointerX();Y#= GetPointerY())
Moving the ship: (within a for/next loop)

*The view offset is then set so that the ship is always in the dead center*

WHAT I WANT TO KNOW:
how can I change
so that it spawns right infront of the SP_Ship[2].Sprite?

No matter how many zeros are added here (I've gone overboard to test) the lazers don't go faster.
How can I make them faster? At the moment my ship can overtake them easily.

Hopefully you can understand! I'm a little tired so this might be a load of random information!

*New question down below*

cheers

Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 22nd May 2014 13:14
Ok, so I've solved the placing of the lazers. Wasn't hard, and I'm baffled as to why I didn't come up with a solution earlier. Basically: sprite offsets.

However, my other question remains! How can I speed up the lazers? Multiplying by vast numbers (>1000) does not seem to alter the speed? I would rather not use impulses as then I would have to call them every frame for a vast amount of "live" lazers.

cheers

Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 22nd May 2014 14:02 Edited at: 22nd May 2014 14:12
Paronamixxe, I had a similar 'max physics' issue with my platform game... You may not like this answer, but the only thing I was able to do was reduce the Physics Scale (for me SetPhysicsScale(0.5) was perfect)... This was however a huge job for me as it of course impacts everything 'Physics' and typically I came across this issue right at the end lol. However, in doing so, enabled me to achieve much higher speeds...

The first thing I do now for all new projects is reduce the Physics Scale to 0.5...

Hope this helps...
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 22nd May 2014 16:12 Edited at: 22nd May 2014 16:16
Yeah... So, using the SetPhysicsScale() command I can now make the lazers faster. Problem is, I want my lazers to travel in a certain direction at a constant speed. This is a problem when my code increases the speed the further away the mouse is from the center (same system for moving the ship.) So the problem is, I need to first set a direction, and then somehow alter values so that they go at a constant chosen speed. If the ship is flying faster, the lazers are slower and if the ship is flying slower, the lazers are faster. But I also need to take into account how fast the ship is moving. So something like this:

( direction ) * ( ( lazer speed ) - ( ship speed ) )

The problem is, is that my ( direction ) variable incorporates both speed and direction. And I'm not sure how I can isolate the direction value. I had a try using ratios, but I couldn't seem to get it to work.

This is my direction variable at the moment:
( x , y )
So if you've got the mouse at the far left of the screen in the middle, it will go very fast towards that. If you have the mouse near the middle of the screen, it will go in the right direction but very slowly. Although, I cannot change this code, because then the direction will be wrong.

In another failed attempt I was using radians to try to get a direction, although converting a direction from degrees to the X,Y coordinates that SetSpritePhysicsVelocity() wants was harder than I thought.

Basically, you shouldn't be able to overtake lazers. They should be fast, and equally fast.

The maths isn't working for me! Please help!

cheers

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 22nd May 2014 17:30
Lasers emit light, so it should be an instantaneous straight line, unless you're taking a huge galactic-scale view! It would be very clever to overtake them.

Maybe these are plasma bursts. In that case they have a velocity and presumably a range before they decay. In that case I'd use an emitter. Plasma bursts are notoriously inaccurate, so make it a feature!

-- Jim - When is there going to be a release?
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 22nd May 2014 18:01 Edited at: 22nd May 2014 18:01
Yeah, I suppose they are closer to plasma bursts than lasers in that case... The range will be X "metres" away from the ship. Emitters would make everything easier... If you could check for collisions with them! Which to my knowledge is not possible. But yeah, the accuracy thing is definitely not a bad idea.

I'm not really sure what you mean by "huge galactic-scale view", the view is centered on your space ship... It turns and flies around whilst still remaining in the dead center of the screen.

cheers

Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 22nd May 2014 20:38
Sorted it out.


Just had to check up on some theory

cheers

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 22nd May 2014 22:32
Quote: "I'm not really sure what you mean by "huge galactic-scale view""


What I meant was, you'd have to be standing back quite a long way to see the front of a light-wave moving.

I write Science Fiction, so I have to be careful about these things or the forums are full of nerds moaning. Not that there are any moaning nerds on here - oh dear, no!

-- Jim - When is there going to be a release?
Paronamixxe
AGK Bronze Backer
12
Years of Service
User Offline
Joined: 10th Feb 2012
Location: Sweden
Posted: 22nd May 2014 23:33
Quote: "What I meant was, you'd have to be standing back quite a long way to see the front of a light-wave moving."


Riiiiiiiight! Although, technically, it would be impossible to see without some particles for the light to pass through.

Quote: "I write Science Fiction, so I have to be careful about these things or the forums are full of nerds moaning. Not that there are any moaning nerds on here - oh dear, no!"


Haha! Ofcourse not! What do you write? Give us (me) a link!

cheers

Login to post a reply

Server time is: 2024-11-25 05:52:23
Your offset time is: 2024-11-25 05:52:23