How do I get the spear to behave the way I want it to?

Clover10123

  • Posts: 11
So, I have a player, three zombies, and a spear. I want my spear to begin at my player, travel where my mouse clicks, and then die when it either hits a zombie or goes off screen.

Right now, when I click, the spear begins at my click, and just sort of wanders off to the bottom right of the screen.  I don't understand why it sort of crawls towards the bottom right corner... and I don't know how to get it to do what I want.
Right now, my player has the following events attached:
-When updating, if right is down, set X-speed to player speed for self... (basically WASD movement)
-When the mouse is pressed, create spear at (x: x of self y: y of self) at Front
My spear has the following events attached:
-When Self hits a zombie - 1st actor/actor of type,  kill self.
-When  Self exits the screen, kill self.
-When updating, set x-speed to [Spear Speed] for self; set y-speed to [Spear Speed] for self.
-When created,  set x to [x of mouse press] for self; set y to [y of mouse press] for self.

The game as it currently runs does this: http://www.stencyl.com/game/play/37802


JeffreyDriver

  • Posts: 1718
I suspect that it's being affected by gravity. You change that under the physics settings.

Unrelated, but an FYI, your game screen is huge. Doesn't fit on my monitor. You might want to consider making it smaller. What's your target platform?
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Clover10123

  • Posts: 11
Eventually, mobile. The screen is 1920 x 1080, since that was the default size for my background images. What size do you think is better?

Also, all of my objects are not affected by gravity, spear included. I double checked to be sure.

JeffreyDriver

  • Posts: 1718
I see in your first post that you have an attribute called 'Spear Speed' and that it's in an X and Y speed block.

X will it it horizontally, and Y vertically. You could use the velocity block to fire the arrow towards the mouse.

As for screen size, 480x320 if designing for mobile. If you're designing for web 800x600 is the safe maximum.
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Clover10123

  • Posts: 11
Okay well... I made a few changes to the dimensions. It seems a bit better.

As for the spear... It's behaving differently, but not as I want it to. It's still drifting to the corner. I'm attaching a screenshot of the changes I made to the spear's events.

Here is the game now: http://www.stencyl.com/game/play/37804

NickamonPoppytail

  • *
  • Posts: 957
Have you gone into Physics and made sure the spear is not affected by gravity?
Currently developing Poppytail 5, Pixeltail, and The Poppytales.

Email: nick.rosemarygames.poppytail@gmail.com

;)

Clover10123

  • Posts: 11
Have you gone into Physics and made sure the spear is not affected by gravity?

Please refer to this post I made:

Eventually, mobile. The screen is 1920 x 1080, since that was the default size for my background images. What size do you think is better?

Also, all of my objects are not affected by gravity, spear included. I double checked to be sure.

NickamonPoppytail

  • *
  • Posts: 957
You could use the Fire Bullet behaviour.
Currently developing Poppytail 5, Pixeltail, and The Poppytales.

Email: nick.rosemarygames.poppytail@gmail.com

;)

JeffreyDriver

  • Posts: 1718
There's a couple of issues with the code that you've posted.  First of all, it's an 'always/updating' event. I'd put it in either a custom event, or attach it to the arrow actor in a 'created' event.

Also, you have two of the same block. You need one block that has the XY values of the mouse calculated in degrees from the launch location.

Thankfully there's an extension to make that easy for you - http://community.stencyl.com/index.php/topic,27769.0.html
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Clover10123

  • Posts: 11
Thank you! That is very helpful. I will try this and then update this post if I succeed,

Clover10123

  • Posts: 11
Sorry for taking so long to respond-- school got crazy busy.

So, I tried all of the suggestions above, but none of them actually fixed the problems, they just changed the way the spear behaved, but I *did* find a solution here: http://www.stencyl.com/help/viewArticle/109

Abigayl showed me how to correctly set the projectile's direction and speed so that it follows my mouse clicks correctly. That is good. My problem isn't entire solved though-- I want to tell my object to STOP moving at the area of the mouse click. In other words, the actor must move a distance relative to the mouse click's position. I don't know how to do this... and there aren't many helpful forums or videos which address this problem.

JeffreyDriver

  • Posts: 1718
Record the X value of the mouse click in an attribute, and when the X value of the spear is equal or greater than that value, stop it. You'll also need to take into account the width of your spear actor. X - width of actor.
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk