Stencyl 3.4.0 is now out. Get it now!

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

Clover10123

  • Posts: 7
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: 1248
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?

Clover10123

  • Posts: 7
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: 1248
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.

Clover10123

  • Posts: 7
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


Clover10123

  • Posts: 7
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.


JeffreyDriver

  • Posts: 1248
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

Clover10123

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