How do I Rotate an Object and have it move toward player?

Get help using Construct 2

Post » Mon Oct 17, 2016 8:52 pm

I am very new to Scirra so I am sure my process is not the same as every one but this makes sense to me...sort of :)

I am working on a rotational shooter from a Udemy class I am taking and I wanted to add an object that moves toward the player and rotates at the same time.

The enemies6 itself has 6 animation panes but I am not using this to achieve the rotation but to have 6 different sprites to provide variety in the enemies that appear on screen...so I am hoping that is not the only way to do a rotation and move.

In short when I use this the object rotates in a big circle I am sure this is an easy fix...hopefully

Image
B
9
S
2
Posts: 104
Reputation: 975

Post » Mon Oct 17, 2016 9:31 pm

If I understand correctly, you want the enemies to face the player and than chase him?

My favorite way of doing this is giving the enemy both the Turret and Bullet behaviors. The Turret will handle rotation and Bullet will give its speed. Perhaps the coolest thing about this method is that you can give the enemies sort of an "awareness area" by changing the Range propriety in Turret.

And then you can have some other events to enable or disable Bullet, to make it stop when it reaches the player, for instance.

https://dl.dropboxusercontent.com/u/391 ... chase.capx
B
11
S
4
Posts: 20
Reputation: 898

Post » Tue Oct 18, 2016 1:57 pm

With my ships they are facing the player and those are working fine, but I am not having them rotate at all. The asteroid objects I want to rotate to give them a bit more life, but I only what them to spin slightly....where is with my above settings the go a full 360 degrees like an orbit cycle....not a spin...if that makes sense.

I will give your suggestion a try and see what I can figure out. As for stopping the bullet I would just set that up in the destroy event with either the player or laser objects.
B
9
S
2
Posts: 104
Reputation: 975

Post » Wed Oct 19, 2016 12:59 am

Oh, I think I get now.

If you want the object to spin around itself, independent of it's moving angle, you'll have to use "Move at angle" instead of "Move forward". Like this:

Image

Then the object will always move toward the player, no matter where it's facing.

Also, remember to use Delta-time

https://www.scirra.com/tutorials/67/delta-time-and-framerate-independence
B
11
S
4
Posts: 20
Reputation: 898

Post » Wed Oct 19, 2016 12:13 pm

Very cool...i'll give this a try!
B
9
S
2
Posts: 104
Reputation: 975

Post » Thu Oct 20, 2016 5:19 pm

Gave it a try but this just causes the asteroid objects to come toward player, which is fine. But the asteroids are still not spinning :) I am sure I am missing something.

Image
B
9
S
2
Posts: 104
Reputation: 975

Post » Mon Oct 24, 2016 6:24 pm

Figured this out. Along with your trick I needed to add a point of origin for the sprites. I assumed it was the center on creation, but apparently not. I think I am good now.
Thanks for the info!
B
9
S
2
Posts: 104
Reputation: 975


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests