How do I change sprite speed when overlapping using physics

Just started using Construct 2? Post your questions here

Post » Sat Nov 05, 2016 4:15 pm

I have a sprite moving around my mobile device's screen via Touch/Tilt controls and Physics. I would like this sprite to slow down when it is overlapping another sprite. I've been able to accomplish this using the "Is Overlapping" condition and the following expression: 'Set Physics velocity to (Self.Physics.VelocityX/2 , Self.Physics.VelocityY/2). Which is good, however, I've read elsewhere in these forums that setting velocity manually is not recommended. So, I've also tried changing the Density, Friction, etc. to slow down my sprite, but this yielded less predictable results than changing the velocity.

Is there a better way to accomplish this? I'm even open to not using physics at all, if another behavior like 8 Direction or Bullet would give me the same realistic motion as Physics does.

I can post the CAPX, or a screen capture of my Even Sheet, if I can get permission to do so.

Thanks and regards!
B
5
Posts: 11
Reputation: 247

Post » Sun Nov 06, 2016 2:08 pm

First of all: you don't need any permission to post parts of your project.
It helps us to solve your problems, so try to provide us with additional info as often as possible.

Now to the solution:
Adjust the linear damping value of the object when it overlaps. Higher value means that the object's velocity decreases faster over time.

If you simply want to for example divide the current speed by 2, you can change the physics behaviour to @R0j0hound 's Chipmunk physics and set a "max speed" that would make it easier for you.
(You would set "max speed" to Self.speed/2 if you want to divide by 2)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Nov 07, 2016 2:48 am

Thanks randomly. I'll give linear damping a try.

This isn't directly related to my physics question, but for future reference, how do I embed a screen capture into my posts, or attach a CAPX?

Thanks again.
B
5
Posts: 11
Reputation: 247

Post » Mon Nov 07, 2016 2:08 pm

1) Include a screen capture:
  • Open up your event sheet/layout at the required position
  • Press "Print" on your keyboard
  • Open up paint (or any image editor)
  • Press "Paste" (or Ctrl+V)
  • Save the image to somewhere accessible
  • Open up your browser, go to http://imgur.com/
  • Upload your image, no login needed.
  • Copy the link to the file (Hover over image->Get share links->BBCode->Remove the [img] tags)
  • Paste the link into your post
Note: Since you don't have 500 reputation points yet, you can't directly link to anything. Make sure to tick "Do not automatically parse URLs" underneath the posting screen.

2) Include a .capx:
  • Open up your project
  • Go to "File" -> "Save as single file"
  • Save to somewhere accessible
  • Upload the file to a filehost, DROPBOX is strongly recommended
  • Paste the download link in your post´
Again: Make sure to tick "Do not automatically parse URLs"
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Nov 07, 2016 2:55 pm

Thanks randomly. I'll work on improving my tarnished reputation, but in the meantime, I'll follow your instructions when posting to the forum.
B
5
Posts: 11
Reputation: 247


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest